Laravel 8 : Attempt to read property "user_id" on int

Viewed 764

I have this error when i want to create my gates for giving permissions to edit the events for the user who create it. Thank you for helping :)

my list page:

@if(Gate::allows('Utilisateur', $events))
        <a class="btn btn-warning" href="{{route('events.edit',$events->id)}}">Editer</a> 
        @endif

EventsController:

 public function edit($id)
    {
        
        if(!Auth::check())
        { 
            return redirect('login');
        }
        $event=Events::findOrFail($id);
    if(!Gate::allows('Utilisateur', Auth::id(), $event)){ 
        abort('403');
    }
    return view('events.edit', ['events' => Events::findOrFail($id)]);
    }

Authserviceprovider:

 public function boot()
    {
        $this->registerPolicies();
        
        Gate::define('Utilisateur', function ($user,$event) {
            // dd("zzzz".$event);
            if($user->id===$event->user_id){
                return 1;
            }
            return 0;


        });
    }
1 Answers
Related