Octobercms/Laravel Get Id Based On Relation
In Octobercms I have a list of Shows (Primary). They have a hasMany relation to Seasons and Seasons belong to the show. Then i have episodes that belong to the season (season hasMany episodes)
In the picture below what I want to do is get the season that belongs to the show, not every season created which is what is showing below. Does anyone with laravel or octobercms knowledge know how i could implement this?
The way octobercms works is that it populates the dropdown by relations or manually via the model. Im doing it by relations:
public $hasMany = [
'episodes' => ['Teranode\Anime\Models\AnimeEpisode', 'key' => 'season_id'],
];
These two links would help but not what im trying to get:
http://octobercms.com/docs/database/relations
http://octobercms.com/docs/backend/relations
Answer
I used Request::segement() to get the Id of the show, in the Episode model under the dropdown function:
public function getSeasonOptions()
{
return Season::where('anime_id', Request::segment(6))->lists('title', 'id');
}
This process can help on nested relations, however the segment amount will have to be modified if you make the url of the primary page deeper.
@haakym the $show = Show::find(1); didnt really help since im trying to get the id automatically not manually. I understand that its suppose to be helpful but that example didnt help
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?