Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thesogafoi's avatar

problem with laravel policy

hey guys in my project i have two model , Student and StudentsData , i created a policy for updating student's data . in dashboard when i use @can method , its understand i want to use my studensDatapolicy but it give me this error

Argument 1 passed to App\Policies\StudentsDataPolicy::update() must be an instance of App\StudentsData, instance of App\Student given, called in /home/sogafoi/Sites/es/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php on line 706"

so here is my codes

This is my AuthServiceProvider

protected $policies = [
        'App\StudentsData' => 'App\Policies\StudentsDataPolicy',
        'App\Student' => 'App\Policies\StudentPolicy'
        // 'App\Model' => 'App\Policies\ModelPolicy',
    ];

this is my students data policy

class StudentsDataPolicy
{
    use HandlesAuthorization;
    public function update(StudentsData $studentsData)
    {
        dd($studentsData);
    }
}

and this is my dashboard controller


public function index()
    {
        $student = auth()->guard('student')->user();
        $studentsData = $student->studentsData()->first();

        return view('front.dashboard', compact(['student', 'studentsData']));
    }

and this is my blade php

@can('update' , $studentsData)
@include('front.includes.student-data-form')
@endcan

thank you

0 likes
2 replies
Ishra's avatar
Ishra
Best Answer
Level 6

I am not 100% sure here, but when i look at one of my own Policies i have two arguments for the update method, the first argument is the user, and the second is the model being acted upon.

    /**
     * Determine whether the user can update the page.
     *
     * @param  User  $user
     * @param  Page  $page
     * @return mixed
     */
    public function update(User $user, Page $page) : bool
    {
         // ...
    }

In your case i think your update method needs to accept two arguments, the first being the currently authenticated user, the second argument being the StudentData you want to check if the user can update.

thesogafoi's avatar

Here my authenticated user is student , but i forget to do this 🙃🙃🙃 its done thank you @ishra

Please or to participate in this conversation.