If you want to use Eloquent then you should:
- Create models associated to materials and materials_lists table.
- Establish relationships between the two models something like this:
In the material model class you should have a one to many type relationship:
public function MaterialsList {
return $this->haveMany ('MatrialLists_ModelName')
}
and a 'belongsTo' type relationship in the opposite way in the MaterialsLists model class.
public function Materials {
return $this->belongsTo ('Materials_ModelName')
}
3. Than you can reference MaterialsList object properties from Materials object like that:
$materialsListCollection = $materials ->MaterialsLists->all();
where $materials is a instantion of Materials Model.
If Eloquent is not mandatory, than you can use join method from Query Builder with DB facade something like that:
$collection = DB::table('materials')
join('material_lists' , 'materials.id' , '=','material_lists,id') ->
join('colors' , 'colors.id' , '=','materials.colors,id') ->
select ('materials.id', 'material_lists.name', 'material_lists.cost',
'colors.code', 'colors.hex', 'colors.name' 'materials.color_cost',
'materials.estimation', 'materials.remarks')
->where('carpet_id' , '2')->get()
Hope it helps :)