Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在从会话()获取空值_Php_Laravel_Session_Flash Message - Fatal编程技术网

Php 正在从会话()获取空值

Php 正在从会话()获取空值,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 { ....

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 {
        ....//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中