Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

984
Views
Illuminate\Database\QueryException SQLSTATE[42S22]: Columna no encontrada: 1054 Columna desconocida

Probé CRUD con Eloquent pero hay un error cuando ejecuto mi programa

Illuminate\Database\QueryException SQLSTATE[42S22]: Columna no encontrada: 1054 Columna desconocida 'pegawai.id' en 'cláusula where' (SQL: select * from pegawai where pegawai . id = 1 limit 1)

Acabo de ver que mi base de datos no es un problema, pero esto sucede cuando quiero ejecutar mi programa. Y adjunto mi controlador

 public function pegawai_edit($id) { $pegawai = Pegawai::find($id); return view('pegawai_edit', ['pegawai' => $pegawai]); }

y este es mi web.php

 Route::get('/pegawai/pegawai_edit/{id}', 'PegawaiController@pegawai_edit');

Esta es mi mesa pegawai :

 +------------+--------------+-----------------+--------------+----------------+---------------------+---------------------+ | pegawai_id | pegawai_nama | pegawai_jabatan | pegawai_umur | pegawai_alamat | created_at | updated_at | +------------+--------------+-----------------+--------------+----------------+---------------------+---------------------+ | 1 | Lucas | NULL | 1 | Jakarta | 2021-09-29 09:07:09 | 2021-09-29 09:07:09 | | 2 | Test | NULL | 2 | TEST | 2021-09-29 09:07:26 | 2021-09-29 09:07:26 | +------------+--------------+-----------------+--------------+----------------+---------------------+---------------------+

estoy usando laravel 8.6 y mysql es mi base de datos

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

De forma predeterminada, el modelo elocuente utiliza la id del campo como clave principal. Como usa pegawai_id en su lugar, debe configurarlo en su modelo

 class Pegawai extends Model { /** * The primary key associated with the table. * * @var string */ protected $primaryKey = 'pegawai_id'; }

una vez configurado, puede usar todos los métodos proporcionados por eloquent sin decirle específicamente que use pegawai_id cada vez

 public function pegawai_edit($id) { $pegawai = Pegawai::find($id); return view('pegawai_edit', ['pegawai' => $pegawai]); }
over 4 years ago · Santiago Trujillo Report

0

Como no respeta el estándar de Laravel, es decir, usa id como el nombre de su columna de id , intente así:

 public function pegawai_edit($id) { $pegawai = Pegawai::where('pegawai_id', $id)->first(); return view('pegawai_edit', ['pegawai' => $pegawai]); }

O modifique solo su modelo de Pegawai , agregando:

 protected $primaryKey = 'pegawai_id';
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!