Php 正在从会话()获取空值
UserController.phpPhp 正在从会话()获取空值,php,laravel,session,flash-message,Php,Laravel,Session,Flash Message,UserController.php public function contactList(Request $request) { //after removing this if function. it is working if ($request->session()->has('id')) { $request->session()->flash('id', 0); } try { ....
public function contactList(Request $request)
{
//after removing this if function. it is working
if ($request->session()->has('id')) {
$request->session()->flash('id', 0);
}
try {
....//Doing Something.
} catch(\PDOException $e){
...//Doing Something.
}
}
public function contactDetail(Request $request,$user_id)
{
try {
DB::connection()->getPdo();
try {
$id = User::findOrFail($user_id);
$request->session()->put('id', $user_id);
... //Doing Something.
} catch(\Exception $ex) {
... //Doing Something.
}
} catch(\PDOException $e) {
... //Doing Something.
}
}
public function sendMessage(Request $request)
{
// dd($request->session()->get('id'));
// dd($request->session()->has('id'));
if (!$request->session()->has('id')) {
return redirect()->to('/');
}
$rand = $this->generateRandomString(6);
return View::make('sendmessage')->with('random',$rand);
}
函数按上述顺序调用,但在调用sendMessage
函数时。session(id)
的值显示为null
。但是调用会话(id)的contactDetail
函数值为1
。为什么会话(id)发回null
值。我现在被卡住了。
函数按上述顺序调用,但在调用
sendMessage
函数时。session(id)
的值显示为null
。但是调用会话(id)的contactDetail
函数值为1
。为什么会话(id)发回null
值。我现在被卡住了 !会话::get('id')
它没有返回假值。因此,将if
和else
代码一起替换为 这些路线在哪里?可能在routes/api.php中?是的。在routes.php中