lundi 26 février 2018

Laravel: Alternate to Session, to show logged in user data

I want to show logged in user data with the user of Laravel in-built class. I have used 'Session' to show the data which makes the code bulky and is not a good practice because we have to always put and flush data.

Here are my codes:

public function login(Request $req) {
    $this->validate($req, [
        'email' => 'required',
        'password' => 'required',
    ]);

    $email = $req->input('email');
    $password = $req->input('password');

    $checkLogin = DB::table('admin')->where(['email'=>$email,'password'=>$password])->first();

    if(count($checkLogin) > 0){
         Session::put('admin-name', $checkLogin->name);
         Session::put('admin-email', $checkLogin->email);
         Session::put('admin-address', $checkLogin->address);
         Session::put('admin-mobile',$checkLogin->mobile);
         Session::put('admin-dob',$checkLogin->dob);
         Session::put('admin-pic',$checkLogin->photo);
         Session::put('admin-password',$checkLogin->password);
         return view('admin');            
    }
    else {
       return Redirect::route('admin-login')->with(['error'=> "Invalid email or Password!!"]);
    }
}

View:

<div class="col-md-7 col-sm-7 col-xs-7 round-img-neighbour">
    <p></p>
    <small><cite title=""> <i class="glyphicon glyphicon-map-marker"></i></cite></small>
</div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire