Filament::getCurrentPanel() always returns true
I am writing a policy to prevent the challenger from editing the duel once he has created it. Here is the controller code:
/**
* Show the form for editing the specified resource.
*/
public function edit(duel $duel)
{
// get the current player's characters count
$count = $this->countActiveCharacters(auth()->user()->id);
// if the player doesn't have any characters
if ($count === 0) {
// display an error instead
return inertia('Duels/NoActiveCharacters');
}
// if the duel was already completed
if($duel->status === STATUS::COMPLETED->value) {
// display a message letting them know
return inertia('Duels/Completed');
}
//lazy load the challenger relationship
$duel->loadMissing('challenger:id,name');
// get offensive moves
$offensive_moves = Move::where('move_type', MoveType::OFFENSIVE)->get(['id', 'name']);
// get defensive moves
$defensive_moves = Move::where('move_type', MoveType::DEFENSIVE)->get(['id', 'name']);
return inertia('Duels/Edit', [
'duel' => fn() => new DuelResource($duel),
'offensive_moves' => fn() => MoveResource::collection($offensive_moves),
'defensive_moves' => fn() => MoveResource::collection($defensive_moves),
]);
} /**
* Show the form for editing the specified resource.
*/
public function edit(duel $duel)
{
// get the current player's characters count
$count = $this->countActiveCharacters(auth()->user()->id);
// if the player doesn't have any characters
if ($count === 0) {
// display an error instead
return inertia('Duels/NoActiveCharacters');
}
// if the duel was already completed
if($duel->status === STATUS::COMPLETED->value) {
// display a message letting them know
return inertia('Duels/Completed');
}
//lazy load the challenger relationship
$duel->loadMissing('challenger:id,name');
// get offensive moves
$offensive_moves = Move::where('move_type', MoveType::OFFENSIVE)->get(['id', 'name']);
// get defensive moves
$defensive_moves = Move::where('move_type', MoveType::DEFENSIVE)->get(['id', 'name']);
return inertia('Duels/Edit', [
'duel' => fn() => new DuelResource($duel),
'offensive_moves' => fn() => MoveResource::collection($offensive_moves),
'defensive_moves' => fn() => MoveResource::collection($defensive_moves),
]);
}Solution
Since you’re not checking against the panelId anyway maybe Filament::isServing() works for you.