isset Permission'a gerek yok. Orada bakmanız gereken şu tablo:
+--------------------+----------+-----------------+-----------+
| owner_type | owner_id | entity_type | entity_id |
+--------------------+----------+-----------------+-----------+
| App\Models\User | 5 | App\Models\Page | 6 |
| App\Models\User | 5 | App\Models\Page | 11 |
| App\Models\Company | 1 | App\Models\Page | 6 |
+--------------------+----------+-----------------+-----------+
Siz bunu daha da basitleştirip şöyle yapabilirsiniz:
+---------+-----------+
| user_id | dealer_id |
+---------+-----------+
| 5 | 6 |
| 5 | 11 |
+---------+-----------+
Bu tabloya göre id's 5 olan user id'si 6 ve 11 olan bayi üzerinde işlem yapabilir demek oluyor.
public function dealerPermissions(): BelongsToMany
{
return $this->belongsToMany(User::class, 'dealer_user');
}
public function hasPermissionForDealer(Dealer|int $dealer): bool
{
return $this->dealerPermissions()
->newPivotStatementForId($dealer)
->exists();
}
$user = User::find(5);
$dealer1 = Dealer::find(11);
$dealer2 = Dealer::find(8);
$user->hasPermissionForDealer($dealer1); // true
$user->hasPermissionForDealer($dealer2); // false