laravel return back with status code example

Example 1: laravel return back with success

return redirect()->back()->with('message', 'IT WORKS!');

Displaying message if it exists:

@if(session()->has('message'))
    <div class="alert alert-success">
        {{ session()->get('message') }}
    </div>
@endif

Example 2: Redirect::route('profile') and with() in laravel

// For a route with the following URI: profile/{id}

return redirect()->route('profile', [$user]);

Example 3: Redirect::route('profile') and with() in laravel

// For a route with the following URI: profile/{id}

return redirect()->route('profile', ['id' => 1]);

Tags:

Php Example