Display success message in laravel

Answers 1
  • Return redirect back with message in laravel and display in view file using session

    return redirect()->back()->with('message', 'IT WORKS!');
        <div class="alert alert-success">
            {{ session()->get('message') }}

    Using this code snippet you can display success message in laravel. First you have to use the with() method on redirect()->back() method in your controller file to assign a value (IT WORKS!) to the key (message). You can keep the key name and value as per your requirements. @if(session()->has('message')) checks if session has key (message) then It displays a message using {{ session()->get('message') }} in your view file. It is helpful when users create, update and delete records and want to see the response of their tasks. If the task is successfully completed then it returns a success message and if the task is not successfully completed then we can return an error message as a response.

  • Back to code snippet queries related laravel

Related queries helps you to understand and may also used for implementation of current code snippet