Laravel 7.2 routing with route group auth guard check with prefixLaravel 7.2 routing with route group auth guard check with prefix

Hello guys if you are new in Laravel 8 then please check below links for more tutorials:

  1. Laravel8 Tutorials
  2. Laravel8 Free Templates

Guys here is the working code snippet for Return success message to Laravel view:

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to Return success message to laravel view? Like I always say that laravel is the best Mvc php framework.

If you want to return success or error message to laravel from laravel controller and then below code will be helpful:
// Controller code
if ($mail) {
    return redirect()
        ->back()
        ->with('success', 'Your message has been sent successfully!');
}

return redirect()
    ->back()
    ->withInput()
    ->with('error', 'There was a failure while sending the message!');

//View code
@if (isset($error))
    <div class="col-sm-12">
        <div class="alert  alert-danger alert-dismissible fade show" role="alert">
          $error
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
        </div>
    </div>
@endif
 If you want to use a session you need to do something like this:
//Controller code
session()->put('error', 'There was a failure while sending the message!');

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

//View Code
@if (session()->has('error'))
    {{ session('error') }}
@endif

 if you have any query related this post then please comment below.

 

Thanks

Jassa

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

4 thoughts on “Return success message to Laravel view”
  1. we can also use:
    Session::flash(‘success’, ‘Permission levels updated.’);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.