php - Laravel 5 - restricting a record from eloquent all() function -


i have accounttype model related user table.

public function users()     {         return $this->hasmany('app\user','account_type_id');     } 

we have built website based on accounttype data (normal user, editor, admin) , want add new type superadmin site admin. don't want account type displayed accounttype::all() code called , in users search result. have used all() function in of places. don't want change everywhere. there way override default function accounttype model?

the best way, (not easiest) create global scope. softdelete trait removes deleted entities queries.

you add global scope accounttype permenently remove superadmin of queries.

ex: accounttype::all() return ['normal user', 'editor']

and

accounttype::withsuperadmin()->all() return previous array plus superamin type.

see : http://softonsofa.com/laravel-5-eloquent-global-scope-how-to/

you don't have use sofa package make works.

open softdelete trait , try understand why does.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -