Skip to content

Nested api controller for fetching child resources

Craig Smith requested to merge nested-api-controller into 3.x

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 named viewing
      • should either of the 2 names in the first method be different, then an array can be passed: ['relationnameInModel' => 'routeParamName']
    • 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

Merge request reports