Laravel - 在会话中存储多个字段

Sel*_*lim 2 php laravel

目前,这仅在会话中存储名字。我需要存储位于同一数据库行中的一些其他字段,例如 user_role 和 city。我怎样才能做到这一点 ?

DashboardContaroller.php

public function getIndex( Request $request )
    {
        $this->data['firstNames'] = \DB::table('tb_users')->orderBy('first_name')->lists('first_name', 'first_name');
        Session::put('firstName', $request->get('first_name'));     
        return view('dashboard.index',$this->data);
    }
Run Code Online (Sandbox Code Playgroud)

索引.blade.php

<form action="" method="post">
{!! Form::select('first_name', $firstNames) !!}
<button type="submit" value="Submit">Go</button>
</form>
Run Code Online (Sandbox Code Playgroud)

看法

<p>{{Session::get('firstName','default value')}}</p>
Run Code Online (Sandbox Code Playgroud)

Mig*_*uel 8

您可以将数据存储为数组:

Session::put('user', ['first_name' => $request->get('first_name'), 'user_role' => Auth::user()->user_role, 'city' => Auth::user()->city]);
Run Code Online (Sandbox Code Playgroud)

看法:

<p>{{Session::get('user')['city']}}</p>
Run Code Online (Sandbox Code Playgroud)