php - IlluminateDatabaseQueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column
Solution:
By default, eloquent model use the field id as the primary key. Since you use pegawai_id instead, you need to set it in your model
class Pegawai extends Model
{
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'pegawai_id';
}
once set, you can use all the methods eloquent provide without specificly telling it to use pegawai_id each time
public function pegawai_edit($id)
{
$pegawai = Pegawai::find($id);
return view('pegawai_edit', ['pegawai' => $pegawai]);
}
Answer
Solution:
As you don't respect the Laravel standard, i.e. use id as the name for your id column, try like this :
public function pegawai_edit($id)
{
$pegawai = Pegawai::where('pegawai_id', $id)->first();
return view('pegawai_edit', ['pegawai' => $pegawai]);
}
Or modify just your Pegawai model, adding :
protected $primaryKey = 'pegawai_id';
Source