I am very new into programming and trying to make some work on Laravel / Voyager admin panel.
I have a Customers table and on this table there is also Customer_Representative field where I can select / assign customer representatives from dropdown list.
What I am trying to achieve is I want each users with their assigned roles (Customer Representative) to list customers only assigned for them.
I am using this below code, but I am not able to see list of customers that other users created.
I can only see the customers I / Admin created but If I login with their details I can see their assigned customers.
So as an admin I want to be able to see all customers, so I can also edit them with my login credentials.
current code I am using is this
public function scopeCurrentUser($query)
{
return $query->where('Customer_Representative', Auth::user()->id);
}
there has been a suggestions as below too ;
public function scopeCurrentUser($query)
{
return $query->when(auth()->user()->is_not_admin, function ($q) {
$q->where('Customer_Representative', auth()->user()->id)
});
}
but it resulted as syntax error, unexpected token "}"
Waiting your feedbacks.