php - How to only show 1 flash message - Laravel

877 Views Asked by At

Hello im newbie in laravel so i really need some help. I want to create a code where only 1 flash message will show. In my case when I update user or store will appear 2 flash message "User updated successfully" and "Store updated successfully". I just want to show only one flash message.

This is my code

<div class="content">
  @include('flash::message')
   @include('adminlte-templates::common.errors')
   <div class="box box-primary">
       <div class="box-body">
           <div class="row">
                {!! Form::model($users, ['route' => ['users.update', $store->user_id], 'method' => 'patch']) !!}

                    @include('users.fields',['user'=>$users])

               {!! Form::close() !!}
             </div>
       </div>
   </div>

<div class="content">
@include('flash::message')
   @include('adminlte-templates::common.errors')
   <div class="box box-primary">
       <div class="box-body">
           <div class="row">
               {!! Form::model($store, ['route' => ['stores.update', $store->id], 'method' => 'patch' , 'files' => true]) !!}

                    @include('stores.fields')


               {!! Form::close() !!}                   
           </div>
       </div>
   </div>

This is the view of 2 flash message from User

This is the view of 2 flash message from Store

1

There are 1 best solutions below

6
On

Remove all flash messages from divs and add only single flash message above.

//add only this above all div and remove others
@include('flash::message')

<div class="content">
    @include('adminlte-templates::common.errors')
    <div class="box box-primary">
        <div class="box-body">
           <div class="row">
               {!! Form::model($users, ['route' => ['users.update', $store->user_id], 'method' => 'patch']) !!}

                @include('users.fields',['user'=>$users])

               {!! Form::close() !!}
           </div>
       </div>
   </div>
</div>

<div class="content">
   @include('adminlte-templates::common.errors')
   <div class="box box-primary">
       <div class="box-body">
           <div class="row">
               {!! Form::model($store, ['route' => ['stores.update', $store->id], 'method' => 'patch' , 'files' => true]) !!}

                @include('stores.fields')


               {!! Form::close() !!}                   
           </div>
       </div>
   </div>
</div>