skip to Main Content

Laravel – How to use the can() method on update routes?

I read here that in Laravel we can use the can method instead of the traditional middleware call on a route. https://laravel.com/docs/11.x/authorization#middleware-actions-that-dont-require-models use AppModelsPost; Route::post('/post', function () { // The current user may create posts... })->can('create', Post::class); Now the traditional…

VIEW QUESTION

Laravel – How rith belongsToMany relation get number of related rows?

In laravel 11 app User model have defined relation : namespace AppModels; use IlluminateFoundationAuthUser as Authenticatable; ... class User extends Authenticatable { public function uncompletedTasks(): belongsToMany { return $this->belongsToMany(Task::class) ->using(TaskUser::class) ->withPivot('supervisor_id') // Reference to "task_user" table ->where('completed', false) ->orderBy('priority', 'desc')…

VIEW QUESTION
Back To Top
Search