Forbidden

You don't have permission to access this resource

🐛 How I Ran Into This

I encountered this issue while attempting to implement a Gate for guest users.

✅ Solution

To resolve the issue, I utilized a nullable type hint for the $user variable, allowing it to be null when a guest user is passed to the gate.

Gate::define('my-gate-name', function (?User $user, Post $post) {
	//
});