How to return error message from controller to view in laravel

You can return error message from controller using return back() method and display in view file using session() in laravel

Answers 2
  • Display error message in laravel view

    --PATH resources\views\<home>.blade.php
    @if(session()->has('error'))
        <div class="alert alert-danger">
            {{ session()->get('error') }}
        </div>
    @endif
    
    0

    This code snippet will display the error message in your laravel view file.

  • Send error message from controller to view in laravel

    --PATH app\Http\Controllers\<YourController>.php
    return back()->with('error', 'The error message here!');
    //OR
    return redirect()->with('error', 'The error message here!');
    
    0

    You have to use code inside your controller's method after performing some task. 

  • Back to code snippet queries related laravel

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