File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,18 @@ public static function boot()
43
43
public static function paginate ($ size )
44
44
{
45
45
$ user = \Auth::user ();
46
- $ parent = parent ::where ('id ' , '<> ' , $ user ->id );
47
46
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
+ }
50
58
}
51
59
52
60
private static function getSubAdminRole ()
@@ -102,6 +110,6 @@ public function users(){
102
110
}
103
111
104
112
public function vehicles (){
105
- return $ this ->hasMany ('App\Vehicle ' , 'id ' , 'final_user_id ' );
113
+ return $ this ->hasMany ('App\Vehicle ' , 'final_user_id ' , 'id ' );
106
114
}
107
115
}
You can’t perform that action at this time.
0 commit comments