Skip to content

Commit 8194e36

Browse files
committed
Ajustes na paginação de usuários e no vinculo de veículos.
1 parent 95c4f4f commit 8194e36

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app/User.php

+12-4
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)