search

Home  >  Q&A  >  body text

Easy way to create multiple flash messages in laravel-9

Is there a way to simplify these three lines to create multiple flash messages?

session()->flash('status', 'error');
session()->flash('title', 'test title');
session()->flash('message', 'test message');

I tried it but it doesn’t work

return view('panel.codes.CodeCrud.create', [
   'categories' => collect(),
   'cards' => collect(),
])->with([
   'status' => 'error',
   'title' => 'test title',
   'message' => 'test message',
]);

P粉969253139P粉969253139242 days ago559

reply all(1)I'll reply

  • P粉852114752

    P粉8521147522024-03-28 00:12:19

    You can pass an array as the second parameter to session()->flash

    session()->flash('status', ['status' => 'error', 'title' => 'test title']);

    reply
    0
  • Cancelreply