Complete the code to define a controller method that handles a request.
public function index() {
return view([1]);
}The view function expects the view name as a string in quotes.
Complete the code to import the base Controller class in Laravel.
use [1];Laravel controllers extend the base Controller class located in App\Http\Controllers\Controller.
Fix the error in the controller method to correctly retrieve all users.
public function showUsers() {
$users = User::[1]();
return view('users.list', ['users' => $users]);
}The correct Eloquent method to get all records is all().
Fill both blanks to define a controller method that validates a request and stores a new post.
public function store(Request $request) {
$validated = $request->[1]([ 'title' => 'required', 'body' => 'required' ]);
Post::[2]($validated);
return redirect()->route('posts.index');
}The validate method checks the request data, and create saves a new model instance.
Fill all three blanks to define a controller method that updates a user and redirects with a success message.
public function update(Request $request, $id) {
$user = User::findOrFail([1]);
$user->update($request->[2]());
return redirect()->route('users.show', [3])->with('success', 'User updated!');
}Use $id to find the user, all() to get all request data, and $id again for the redirect parameter.