how to call a middlaware when calling a route in controller

  backend, laravel, middleware, php, routes

this is where I need middlware

 public function getFileAttribute()
    return route('backend.file_url', [
        'path' => $this->attributes['attachment'],

this is my route

    Route::get('file-url', '[email protected]')->name('file_url');

I want to use middlaware Like this but not in web.php or api.php
I need it in controller

    Route::get('/download/{ticket}', '[email protected]')->name('download')->middleware(['can:download,ticket']);

Source: Laravel

Leave a Reply