Nested api controller for fetching child resources
Created by: phpsa
This method allows us to create a nested child API controller route
-
artisan make:api:controller ChildController --parent=Parent -
Confirm both the following methods work for relations in the ChildController -
protected string $parentModel = Viewing::class;
. -- this is where the relation and the url key will be the strtolower of the base classname, ie/api/viewing/{viewing}/notes
and in the Notes model the method to get the related record is namedviewing
- should either of the 2 names in the first method be different, then an array can be passed:
['relationnameInModel' => 'routeParamName']
- should either of the 2 names in the first method be different, then an array can be passed:
-
confirm index method gets only the records related to the specific parent -
confirm create method auto-adds the id to the created record -
Show / Update/ Delete should validate based on parent / child
-