dsdsds12222 2016-12-21 13:49
浏览 92
已采纳

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

Currently this is storing only first_name in session. I need to store some other fields which are in the same database row like user_role and city. How can I do that ?

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);
    }

index.blade.php

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

View

<p>{{Session::get('firstName','default value')}}</p>
  • 写回答

3条回答 默认 最新

  • douci1918 2016-12-21 13:54
    关注

    You can store the data as array:

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

    View:

    <p>{{Session::get('user')['city']}}</p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题