Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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);
});

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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']);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading