Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

UsmanFarzand's avatar

How i can pass Session to View

''' public function index() { $data = User::find('id');

    $alerts = array('message'=>'Down Time of System', 'cls'=> 'success');

    return view('client.dashboard',['data' => $data])->with('alerts',$alerts);
} '''

in view

'''

@if(session('alerts'))

<div class="m-alert m-alert--outline m-alert--outline-2x alert alert-{{session('alerts.cls')}} alert-dismissible fade show"
     role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    </button>
    {{session('alerts.message')}}
</div>

@endif '''

alerts not working not and no error show ... any help how i can get seesion value

0 likes
2 replies
s4muel's avatar

you're passing in ->with('alerts', $alerts); so instead of session('alerts') use just $alerts and $alerts['message'] respectively

edoc's avatar
edoc
Best Answer
Level 24

You forgot to add the array into the session.

change this

 $alerts = array('message'=>'Down Time of System', 'cls'=> 'success');

    return view('client.dashboard',['data' => $data])->with('alerts',$alerts);

to

session()->flash('alerts', ['message'=>'Down Time of System', 'cls'=> 'success']);

    return view('client.dashboard',['data' => $data]);
2 likes

Please or to participate in this conversation.