devhamx
242
10
Laravel

how to solve SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause'

Posted 2 months ago by devhamx

im getting this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select count(*) as aggregate from assures where cin = a and id <> 1)

Although i defined the primary key for the table in the model

My model

class Assure extends Model{
protected $table = 'assures';
    protected $primaryKey = 'id_assure';
    public function quittances(){
    return $this->hasMany('App\Quittance');

} }

My sql query in the controller

try{
$assure = Assure::where('cin',$request->input('cin'))->firstOrFail();
} catch (ModelNotFoundException $ex) { $assure = new Assure();}

Please sign in or create an account to participate in this conversation.