File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,10 +43,18 @@ public static function boot()
4343 public static function paginate ($ size )
4444 {
4545 $ user = \Auth::user ();
46- $ parent = parent ::where ('id ' , '<> ' , $ user ->id );
4746 if ($ user ->isSubAdmin ())
48- $ parent = $ parent ->where (["created_by " => $ user ->id ]);
49- return $ parent ->paginate ($ size );
47+ return parent ::where ('id ' , '<> ' , $ user ->id )->where (["created_by " => $ user ->id ])->paginate ($ size );
48+ else if ($ user ->isAdmin ()){
49+ $ usersId = [];
50+ Role::where ('slug ' , 'admin ' )->orWhere ('slug ' , 'subadmin ' )->get ()->each (function ($ role ) use (&$ usersId ) {
51+ return $ role ->users ->each (function ($ user ) use (&$ usersId ){
52+ $ usersId [] = $ user ->id ;
53+ });
54+ });
55+ sort ($ usersId );
56+ return parent ::where ('id ' , '<> ' , $ user ->id )->whereIn ('id ' , $ usersId )->paginate ($ size );
57+ }
5058 }
5159
5260 private static function getSubAdminRole ()
@@ -102,6 +110,6 @@ public function users(){
102110 }
103111
104112 public function vehicles (){
105- return $ this ->hasMany ('App\Vehicle ' , 'id ' , 'final_user_id ' );
113+ return $ this ->hasMany ('App\Vehicle ' , 'final_user_id ' , 'id ' );
106114 }
107115}
You can’t perform that action at this time.
0 commit comments