The issue might be that the player property is not defined in the UpdatePlayerRequest class. You can define it by adding a constructor to the class and passing the Player instance to it. Here's an example:
class UpdatePlayerRequest extends FormRequest
{
private $player;
public function __construct(Player $player)
{
$this->player = $player;
}
public function authorize(): bool
{
return $this->user()->can('update', $this->player);
}
public function rules(): array
{
return [
//
];
}
}
Then, in your PlayerController, you can pass the Player instance to the UpdatePlayerRequest constructor like this:
public function update(Player $player, UpdatePlayerRequest $request)
{
$player = $this->playerService->updatePlayer($player, $request->validated());
return redirect('/games/'.$player->game_id);
}
This should ensure that the authorize method has access to the Player instance and can properly authorize the request.