laravel 11 here
in web.php
Route::resource('event', EventController::class);
works ok
when i replace this line by
Route::get('/event', [EventController::class, 'index'])->name('event.index');
Route::get('/event/{id}', [EventController::class, 'show'])->name('event.show');
show doesn't work anymore and send this error :
Attempt to read property "description" on null
because the object is not passed to the show method. i saw this with a dd($event); $event is the object that should be passed to the show method.
i need to detail each route instead of simply using Route::resource because index and show should be public and the rest should be authenticated.
any hint ? thank you
the Route::resource should work the same way the two Route::get lines work
EDIT it seems like if i write
Route::get('event/{event}', [EventController::class, 'show'])->name('event.show');
it works but i don't get why. (i put event instead of id)
i did the same as in this video https://www.youtube.com/watch?v=eUNWzJUvkCA but it doesn't work the same when i do it
EDIT my routes look like this now :
//guest
Route::get('event', [EventController::class, 'index'])->name('event.index');
Route::get('event/{event}', [EventController::class, 'show'])->name('event.show');
// authenticated
Route::middleware(['auth'])->group(function () {
Route::get('/event/create', [EventController::class, 'create'])->name('event.create');
Route::post('/event', [EventController::class, 'store'])->name('event.store');
Route::get('/event/{event}/edit', [EventController::class, 'edit'])->name('event.edit');
Route::put('/event/{event}', [EventController::class, 'update'])->name('event.update');
Route::delete('/event/{event}', [EventController::class, 'destroy'])->name('event.destroy');
});
but localhost:8000/event/create returns a 404. how strange. any hint ?