我尝试使用ajax登录管理员。但是我遇到了这个错误。我不知道第0列来自哪里。
SQLSTATE [42S22]:未找到列:1054“where”中的未知列“0” 子句''(SQL:select * from
users
where0
= admin limit 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 :(得分:3)
问题是您的$admin
数组。你已经混合了两种用于创建数组的语法,并且你不小心创建了一个数组数组。
您需要将$admin
数组更改为:
$admin = array(
'username'=>$username,
'password'=>$password,
'level'=>1
);
或:
$admin = [
'username'=>$username,
'password'=>$password,
'level'=>1
];