会话中的数据仅在页面刷新之前存在:(如何让它活得更久?
index.blade.php
<form action="" method="post">
{!! Form::select('first_name', $firstNames) !!}
<button type="submit" value="Submit">Go</button>
</form>
DashboardController.php
public function getIndex( Request $request )
{
$this->data['online_users'] = \DB::table('tb_users')->orderBy('last_activity','desc')->limit(10)->get();
$this->data['firstNames'] = \DB::table('tb_users')->orderBy('first_name')->lists('first_name', 'id');
print_r($this->data['firstNames']);
\Session::put('firstNames',Input::get('first_name'));
$this->data['active'] = '';
return view('dashboard.index',$this->data);
}
答案 0 :(得分:0)
你可以这样做:
return view('dashboard.index')->with(['data', $this->data]);
答案 1 :(得分:0)
使用compact
$data['online_users'] = \DB::table('tb_users')->orderBy('last_activity','desc')->limit(10)->get();
$data['firstNames'] = \DB::table('tb_users')->orderBy('first_name')->lists('first_name', 'id');
$data['firstName'] = Input::get('first_name'));
$data['active'] = '';
return view('dashboard.index', compact('data'));
然后您将能够访问所有值:
{{ $data['firstNames'] }}
{{ $data['firstName'] }}
{{ $data['online_users'] }}
{{ $data['active'] }}
在这种情况下不需要会话