Complete the code to define a controller method that returns a view named 'welcome'.
public function index() {
return view('[1]');
}The view function loads the Blade template named 'welcome'. This is the correct view to return.
Complete the code to define a controller method that accepts a parameter $id and returns it.
public function show([1]) { return $id; }
The method parameter must be $id to match the variable used inside the method.
Fix the error in the controller method to correctly redirect to the 'home' route.
public function redirectToHome() {
return [1]('home');
}view instead of redirect causes the method to return a view, not a redirect.route alone without redirect does not perform a redirect.The redirect helper is used to send the user to another URL or route.
Fill both blanks to define a controller method that validates a request and stores a new user.
public function store(Request $request) {
$validated = $request->[1]([ 'email' => 'required|email' ]);
User::[2]($validated);
return redirect()->route('users.index');
}save on the model class instead of an instance.check which is not a Laravel method.The validate method checks the request data. The create method saves a new user with the validated data.
Fill all three blanks to define a controller method that updates a user and redirects back with a success message.
public function update(Request $request, User $user) {
$data = $request->[1]([ 'name' => 'required' ]);
$user->[2]($data);
return redirect()->[3]('users.show', $user->id)->with('status', 'User updated!');
}save instead of update on the model instance.redirect()->route incorrectly without parameters.The validate method checks the data, update changes the user record, and route generates the redirect URL.