This table connects the ingredients, the unit the recipe should be measured with, and the recipe which the ingredient belongs to.
Now with Eloquent I know I can do a 2 way m-m relationship. However, as you may have guessed, it doesn't suit my needs. Is there any way I can do a 3 ways m-m relationship with Eloquent? It doesn't have to be a 3rd package, you can also show a snippet of how I would do that (How would I retrieve all the ingredients with their units for a certain recipe, how would I attach a unit/ingredient to a recipe etc.)
@blackbird I'm not sure how eager loading would help me here? There isn't a nested relationship here which I can use this eager loading with. I need to return the ingredient actual name plus the chosen unit for the ingredient for a particular recipe.
Well if you setup your many to many relations then you can nest them right when retrieving? I hope I understand you correct now!
Movie.php
class Movie extends Model {
...
public function actors()
{
return $this->belongsToMany('App\Actor');
}
public function genres()
{
return $this->morphMany('App\Genre', 'genreable');
}
public function producer()
{
return $this->belongsTo('App\Producer');
}
}
Then in your controller you can do something like this
public function all()
{
return Movie::with(['actors', 'producer', 'genres'])->get();
}
@bestmomo it doesn't seem that it has been updated to laravel 5 yet. I will take a look at the source code so maybe I can figure out what was done there.
@kfirba In fact I created the feature, but it was joechilds, who made it a package. That said, I'm not sure, but I suppose there's nothing to adjust for L5 there, so just try it out.
If it doesn't work, then let me know and I will take a look. I'm working on something bigger, kinda eloquent extensions currently.
@JarekTkaczyk If your time estimation for that eloquent extension is over the corner, I wouldn't mind waiting. I will try the package and let you know somewhen this/next week
@kfirba did you figure out how to make that call to get a recipe with all its ingredients with the unit? I'd really ikke to know how to do this as I have the exact same issue.