return redirect back with error message laravel code example

Example 1: laravel redirect back with errors and input

return redirect()->back()->withInput();

Example 2: return redirect with message laravel

Route::post('user/profile', function () {
    // Update the user's profile...

    return redirect('dashboard')->with('status', 'Profile updated!');
});

Example 3: laravel redirect with message to section

//redirct to previous page with message at a specific setion :)
return redirect(url()->previous() .'#comments')->with('success', 'Data Your Comment has been created successfully');

Tags:

Php Example