Route::resource('photos', PhotoController::class);. What URL and HTTP method will trigger the edit method of PhotoController?The edit method is accessed via a GET request to /photos/{photo}/edit. This URL shows a form to edit the photo resource.
update method is called when submitting an edit form. What HTTP method does $request->method() return inside the update method?The update method responds to PUT or PATCH requests. Standard Laravel edit forms use @method('PUT'), so $request->method() returns PUT.
index and show methods. Which route registration is correct?The only method limits the resource routes to specified methods. except excludes methods but is not the best choice here. methods and filter do not exist.
public function show(Post $post) { return view('post.show', compact('post')); }And this route registration:
Route::resource('posts', PostController::class);Why might
$post be null or cause an error?Laravel uses route model binding by matching the route parameter name with the method parameter name. If they differ, Laravel cannot inject the model instance.
Resource controllers provide a clean, standardized way to create all CRUD routes with proper HTTP verbs and route names, reducing repetitive code and improving maintainability.
