Home > Software design >  I need to make auth on all resource controller except show class
I need to make auth on all resource controller except show class

Time:09-22

I need to make auth on all resource controller except show class

Route::get('/', function () {
    return view('welcome');
});



Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified'
])->group(function () {
    Route::resource('pdfs', PdfController::class);
});

CodePudding user response:

Option 1: You can achieve it with something like this in your route:

Route::resource('pdfs', PdfController::class)->only(['show']);

Route::middleware([
    'auth:sanctum',
    config('jetstream.auth_session'),
    'verified'
])->group(function () {
    Route::resource('pdfs', PdfController::class)->except(['show']);
});

Option 2: You can write a route without the middleware like bellow:

Route::resource('pdfs', PdfController::class)

And in your controller:

public function __construct()
{
    $this->middleware([
        'auth:sanctum',
        config('jetstream.auth_session'),
        'verified'
    ])->except(['show']);
}
  • Related