osb/app/Traits/ScopeServiceUserAuthorised.php
2022-04-20 12:43:10 +10:00

22 lines
452 B
PHP

<?php
/**
* Add a ScopeAuthorised to an Eloquent Model
* This will help limit the scope of accounts that a user can see.
*/
namespace App\Traits;
use App\Models\User;
trait ScopeServiceUserAuthorised
{
/**
* Only query records that the user is authorised to see
*/
public function scopeServiceUserAuthorised($query,User $uo)
{
return $query
->whereIN('services.account_id',$uo->all_accounts()->pluck('id')->unique()->toArray());
}
}