Routind Master-Detail Laravel 4
-
21-12-2019 - |
Question
good morning,
someone who can help me, I need to create a route between father son model to model, leading to the url the id of the parent, which is called Master-Detail.
My model Detail Inventory:
return $this->hasMany('Inventory');
My model Master Dependence:
return $this->belongsTo('Dependence', 'dependece_id', 'id');
I want something like this:
localhost:8000/dependences/25/inventories
Thank you for your cooperation
Solution
Route::get('dependencies/{id}/inventories', function($dependencyId)
{
$dependency = Dependency::findOrFail($dependencyId);
dd($dependency->integory->toArray());
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow