skip to Main Content

Application doesn’t show messages as it should.

I tried returning back with message in RoleController. Redirecting works fine, but I can’t see any messages. There is multiple functions like this, none of them show messages.

public function store(Request $request)
    {
        $validated = $request->validate(['name' => ['required', 'min:3']]);
        Role::create($validated);

        return back()->with('message', 'Role created successfully.');
    }

And this code below is in admin.layout blade.

@if (Session::has('message'))
<div class="alert alert-warning alert-dismissible fade show" role="alert">
    {{ Session::get('message') }}
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif

I googled this many many times but can’t find a solution. This worked fine month ago, but when I continued with this yesterday, it suddenly stopped working. Php version hasn’t changed, it’s 8.0.2. I also tried flash-messages with no help.
Sorry, not a native english speaker.

edit / I have also cleared cache with php artisan.

4

Answers


  1. Chosen as BEST ANSWER

    Now it's working. I needed to modify Kernel.php and remove IlluminateSessionMiddlewareStartSession::class, under the protected $middlewareGroups.


  2. I think you can try this…

    @if ($message = Session::get('message'))
    <div class="alert alert-warning alert-dismissible fade show" role="alert">
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            <strong>{{ $message }}</strong>
    </div>
    @endif
    
    Login or Signup to reply.
  3. Please try one time with this one

    return redirect()->back()->with('message', 'Role created successfully.');
    
    Login or Signup to reply.
  4. try this

    In Controller

    return redirect()->route('admin.listing')->with('message', 'Role created successfully.');
    

    In Blade file

    @if (Session::has('message'))
        <div class="alert alert-warning alert-dismissible fade show" role="alert">
            {{ Session::get('message') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif
    
    
    
      
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search