dimanche 3 avril 2016

SQLSTATE[42S22] In Laravel 5

I try to make login for admin using ajax.But I run into this error.I don't know where is column 0 come out.

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from users where 0 = admin limit 1)

Here is my code

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

Model

<?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;


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire