Laravel 5.4 Show flash error and success messages in different ways

laravel 6 flash message
laravel redirect with flash message
laravel flash message from javascript
laravel session flash message not working
how to show error message in laravel blade
how to display session flash message in laravel
laravel session msg
alert-success message in bootstrap

Method from my PostController

public function store(PostRequest $request)
    {
        if (Post::create($request->all())) {
            $request->session()->flash('status', 'Post was successfully added!');
        } else {
            $request->session()->flash('status', 'Error!');
        }
        return redirect('/');
    }

index view

<?php if(session()->has('status')){
        echo '<div style="text-align: center">';
        echo session()->get('status');
        echo '</div>';
    }?>

How to show error and success messages in different ways?

You can use something like this:

public function store(PostRequest $request) {
    if (Post::create($request->all())) {
        $request->session()->flash('message.level', 'success');
        $request->session()->flash('message.content', 'Post was successfully added!');
    } else {
        $request->session()->flash('message.level', 'danger');
        $request->session()->flash('message.content', 'Error!');
    }
    return redirect('/');
}

In your blade file:

@if(session()->has('message.level'))
    <div class="alert alert-{{ session('message.level') }}"> 
    {!! session('message.content') !!}
    </div>
@endif

The code above uses bootstrap's alert css classes for styling and is inspired by Jeffrey Way's Laracasts Flash package

Laravel, Method from my PostController public function store(PostRequest $request) { if (​Post::create($request->all()))  Step 1: flash-message blade file. In first step we will create new blade file flash-message.blade.php.In this file we will write code of bootstrap alert and check which messages come.

You can display flash messages in this way:

In your controller:

$request->session()->flash('success', 'Record successfully added!');
//OR
$request->session()->flash('warning', 'Record not added!');

In your veiw:

@foreach (['danger', 'warning', 'success', 'info'] as $key)
 @if(Session::has($key))
     <p class="alert alert-{{ $key }}">{{ Session::get($key) }}</p>
 @endif
@endforeach

Implement Flash Message with Laravel 5.7, In this tutorial i added several way to give flash message like redirect with success message, redirect with error message, redirect with warning  Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

  1. Write code like this in your Blade template:

    @if(Session::has('error'))
        <p class="alert alert-danger">{{ Session::get('error') }}</p>
    @endif
    
  2. Write code like this in your Controller:

    Session::flash('error', 'Some thing is wrong. Please try again');
    Redirect::to(path to blade file route);
    

How to get a success message, laravel 5.7 flash message example, laravel 5.7 display flash message I added several ways to give a flash message like redirect with success message, redirect with an error message, redirect with a warning message and  If available, Laravel automatically adds the current user's ID to every exception's log message as contextual data. You may define your own global contextual data by overriding the context method of your application's App\Exceptions\Handler class.

Session flash message not working after redirect route, At the moment I've only gotten the errors to show. my contro. I'm using laravel 4 and I created a form and I would like to have a success message show. redirect the user back. http://laravel.com/docs/4.2/session#flash-data Flash Message with Session Laravel 5 4 Session Flash Message Laravel, Show Notification Flash Laravel. Simple trick for show notification with flash messege session on laravel 5.4. #related Using

Laravel 5 5 tutorial 33 fixing success flash message not showing , I have problem with session flash message working. How use standard redirect​()->route()->with() Session::flash("flash_notification", [ "level" => "success", "​message" => "Berhasil menyimpan As you all have noticed, there can be several reasons why flash messages may not show up in Laravel 5.2 or  Likewise, you may use the * character when specifying your validation messages in your language files, making it a breeze to use a single validation message for array based fields: 'custom' => [ 'person.*.email' => [ 'unique' => 'Each person must have a unique e-mail address', ] ],

Flash Message with Session Laravel 5 4, Easy Flash Messages for Your Laravel App. This composer package offers a Twitter Bootstrap optimized flash messaging setup for your Laravel applications. The Illuminate\Notifications\Notifiable trait, which is included on Laravel's default App\User model, includes a notifications Eloquent relationship that returns the notifications for the entity. To fetch notifications, you may access this method like any other Eloquent relationship.