Skip to content

[Bug]: Policy references not linked using Gate::authorize() with model instance #264

Open
@bakerkretzmar

Description

@bakerkretzmar

Extension Version

0.1.20

PHP Binary

Valet

Operating System

macOS

What happened?

Possibly related to #225.

Policy references are not linked when passing Gate::authorize() a model instance.

This works, create is linked to the expected class, ProgramPolicy:

Gate::authorize('create', Program::class)

This doesn't work, there's no link ($program is a Program model instance):

Gate::authorize('update', $program)

Vanilla setup, Program is a regular model, ProgramPolicy exists in the default location and has an update method with the default type hints, etc. Reproduced in two different apps.

Mimimal Code Sample

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Support\Facades\Gate;

class UserController extends Controller
{
    public function update(User $user)
    {
        Gate::authorize('update', $user);
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions