Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
SQL column not found although it exists

I'm using the Laravel framework to create a prototype and need to output an individual article from a database based on it's ID. Seems straightforward but I keep getting the following error when I query the database:

QueryException in Connection.php line 647:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'articles.id' in 'where clause' (SQL: select * from `articles` where `articles`.`id` = 1 limit 1)

I'm trying to retrieve a specific article based on the database column article_id via the articles table in my Article model. I am using a resource route thus the method name 'show' - so I can access via article/{$article_id} in the URL.

Here is my controller:

public function show($article_id) {

    $article = Article::find($article_id);
    $article->toArray();

    return view('articles.view', array('article' => $article));

}

There is no articles.id. It should be articles_id. Am I missing something obvious here?

Thanks in advance, any pointers much appreciated.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The find command looks for whatever is set as the primary key, which by default is id. You can change the primary key in your model:

class Article {

    protected $table = 'articles';
    protected $primaryKey = 'articles_id';

}
over 4 years ago · Santiago Trujillo Denunciar

0

find() searched by primary key, so change the query to:

$article = Article::where('article_id', $article_id)->first();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda