Laravel - Authorization - Gates Supplying Additional Context

The gate methods for authorizing abilities (allows, denies, check, any, none, authorize, can, cannot) and the authorization Blade directives (@can, @cannot, @canany) can receive an array as their second argument. These array elements are passed as parameters to the gate closure, and can be used for additional context when making authorization decisions:

    
    use App\Models\Category;
    use App\Models\User;
    use Illuminate\Support\Facades\Gate;
    
    Gate::define('create-post', function (User $user, Category $category, $pinned) {
        if (! $user->canPublishToGroup($category->group)) {
            return false;
        } elseif ($pinned && ! $user->canPinPosts()) {
            return false;
        }
    
        return true;
    });
    
    if (Gate::check('create-post', [$category, $pinned])) {
        // The user can create the post...
    }