Query table row by column name in Laravel?

3

In Laravel I want to query a record in the database for id of the table, but the code below only queries if the column nomenclature is id

$prod = $this->produto->find(3)

If the column name is prod_id for example, how can I return the record?

    
asked by anonymous 20.07.2017 / 22:38

1 answer

3
Produto::where('prod_id',123)->get();

or

Produto::where('prod_id',123)->first();

Where Produto is the Model class

Update

Laravel by default uses the id column as the id of its Models, to change it and use prod_id in the find() function you need change your Model as follows:

class Produto extends Eloquent {

    protected $primaryKey = 'prod_id';

}
    
20.07.2017 / 22:45