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条)

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入