2016-04-03 32 views
0

我嘗試使用ajax進行admin登錄。但是我運行進入這個錯誤。我不知道列0從哪裏來。SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'0'(SQL:select * from users where 0 = admin limit 1)

SQLSTATE [42S22]:柱未找到:1054未知列 '0' '其中 子句'(SQL:SELECT * FROM users其中0 =管理員極限1)

這是我的代碼

public function login() 
{ 
    $username= Input::get('username'); 
    $password= Input::get('password'); 
    $admin=array([ 
     'username'=>$username, 
     'password'=>$password, 
     'level'=>1 
     ]); 
    if ($this->auth->attempt($admin)) { 
     return "ok"; 
    } 
    else { 
     return "fail"; 
    } 
} 

型號

<?php namespace App; 

use Illuminate\Auth\Authenticatable; 
use Illuminate\Database\Eloquent\Model; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 


class User extends Model implements AuthenticatableContract 
{ 

    use Authenticatable; 

    /** 
    * The database table used by the model. 
    * 
    * @var string 
    */ 
    protected $table = 'users'; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = ["username","password",'level']; 

    /** 
    * The attributes excluded from the model's JSON form. 
    * 
    * @var array 
    */ 
    protected $hidden = ['password']; 
    public $timestamps = false; 


} 
+0

添加完整的錯誤堆棧中的問題。 – Vikas

+0

@Vikas我剛剛更新了錯誤 –

回答

1

問題是您的$admin陣列。你已經混合了創建數組的兩種語法,並且意外地創建了一個數組數組。

您需要將$admin陣列更改爲:

$admin = array(
    'username'=>$username, 
    'password'=>$password, 
    'level'=>1 
); 

或:

$admin = [ 
    'username'=>$username, 
    'password'=>$password, 
    'level'=>1 
]; 
+1

感謝您reply.I修復它。 –

相關問題