Retrieve related records based on slug

Posted 2 years ago by ekrist1

I have two tables. One division table and one seasontable. The seasontable records is related to the divisiontable (hasOne). I’m trying to use a slug to only show seasontable records equal to the slug field on the divsiontable.

I´m able to retrieve all related tables, but i can´t find a way to only retrieve a selection based on the url slug. Any ideas how to use eloquent to achieve this?

Model: public function show($slugdivision, Request $reguest) { //$seasontables = Seasontable::where('Seasontable->seasondivision->slugdivision', $slugdivision)->get(); $seasontables = Seasontable::with('seasondivision')->get(); return $seasontables; }

Result: [{"id":1,"wongames":5,"lostgames":3,"tiegames":2,"playedgames":10,"pointsgames":32,"goalswon":9,"goalslost":7,"rank":3,"teams_id":1,"years_id":1,"division_id":1,"created_at":"2016-09-11 00:00:00","updated_at":"2016-09-11 00:00:00","seasondivision":{"id":1,"divisionname":"tippeligaen","divisiondescription":"lorem","created_at":"2016-09-06 00:00:00","updated_at":"2016-09-05 00:00:00","slugdivision":"tippeligan"}},

{"id":2,"wongames":10,"lostgames":10,"tiegames":3,"playedgames":13,"pointsgames":44,"goalswon":3,"goalslost":4,"rank":4,"teams_id":2,"years_id":1,"division_id":1,"created_at":"2016-09-12 00:00:00","updated_at":"2016-09-12 00:00:00","seasondivision":{"id":1,"divisionname":"tippeligaen","divisiondescription":"lorem","created_at":"2016-09-06 00:00:00","updated_at":"2016-09-05 00:00:00","slugdivision":"tippeligan"}}]

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.