Got stacked in laravel eloquent relationships. i have two tables.
fuel contains
- id, fuel_name, fuel_rate
machine contains
-
id, machine_name, machine_rate fuel_id
fields.
fuel_id is a foriegn key.
I have tried some examples from laravel.com
in Machine.php
class Machine extends Model
{
protected $table = 'machine';
public function machineinfo()
{
return $this->hasMany('App\Fuel','id');
}
}
and in controller
$items = Machine::find(1)->machineinfo;
i want to see machine name, machine code, fuel name and fuel rate in output.
but the output is
Column not found: 1054 Unknown column 'fuel.machine_id' in 'where clause' (SQL: select * from fuel
where fuel
.machine_id
= 1 and fuel
.machine_id
is not null)
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2X1qKXn
via IFTTT
Aucun commentaire:
Enregistrer un commentaire