Monday, November 23, 2020

Return success message to laravel view

Laravel 7.2 routing with route group auth guard check with prefix

Return success message to laravel view

Hello to all, welcome to 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()
        ->with('success', 'Your message has been sent successfully!');

return redirect()
    ->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">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
 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()

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

 if you have any query related this post then please do ask.


Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.


Leave a Reply

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