简体   繁体   中英

getting null value from session()

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

Functions are calling in above sequence but when calling sendMessage function. value of session(id) is showing null . but calling contactDetail function value of session(id) is 1 . why session(id) sending back null value? . . . I'm getting stuck now. Functions are calling in above sequence but when calling sendMessage function. value of session(id) is showing null . but calling contactDetail function value of session(id) is 1 . why session(id) sending back null value? . . . I'm getting stuck now.

!session::get('id') it is not returning false value. so replace if & else code with together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM