public function index() { // some operation return redirect('/'); }
public function store(Request $request) { // some operation return redirect('/')->with('message', 'Data saved successfully!'); }
public function show($id) { $data = SomeModel::find($id); if($data == null){ return redirect('/error')->with('message', 'Data not found!'); } return view('show', compact('data')); }In this example, the controller checks if the requested data exists in the database, and if it does not exist, the user will be redirected to the error page with an error message. If the data exists, it will be passed to the view. The PHP Controller Redirect is a feature of the Laravel framework, which is a comprehensive package library for building web applications.