繁体   English   中英

我想从DB :: Select get()获取一个'INT'值

[英]I want to get a 'INT' value from a DB::Select get()

我想进行简单的登录并将每个用户重定向到其私人页面,因此每个用户都将拥有自己的页面。 像www.example.com/user1。

这是针对我正在为此工作开发的新应用程序。

public function login(request $req){
    $username = $req->input('username');
    $password = $req->input('password');
    $type = 1;
    $checklogin = DB::table('users')->where(['username'=>$username,'password'=>$password])->get();
    $checktype = DB::table('users')->where(['username'=>$username,'password'=>$password,'type'=>$type])->get();        
    $url2 = DB::table('users')->where(['username'=>$username,'password'=>$password])->get('id');
    if(count($checklogin) >0){
        if (count($checktype) ==1) {
            header("Location: /admin/$url2", true, 301);
            exit();
        }else{
            if ($url2 == 4) {              
                echo "$url2";
            }
        }
    }else{
        return view('loginfailed');
    }
}
}

重定向的网址是:“ http:// localhost:8000 / admin / [%7B%22id%22:2%7D]

您可以将id提取为

// fetching 1 record and then id of it
$url2 = DB::table('users')->where(['username'=>$username,'password'=>$password])->first()->id;
public function login(request $req){ $username = $req->input('username'); $password = $req->input('password'); $checklogin = DB::table('users')->select('type')->where(['username'=>$username,'password'=>$password])->get()->first(); if(count($checklogin){ if ($checklogin->type ==1) { header("Location: /admin/$url2", true, 301); exit(); }elseif ($checklogin->type == 4) { //do something else } }else{ return view('loginfailed'); } } }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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