I have mentioned the routes as follow. I tried a few ways to achieve the model binding but no success.
1st attempt
I tried to have the parameter as {organization:slug} but only empty array is returned.
2nd attempt
I put getRouteKeyName function in the Organization model as per laravel docs and keep route parameter as {organization} but same empty array is returned.
3rd Third attempt
I tried to get the organization by sending ID instead of 'slug' in the api request and still the same.
If I pass the plain slug or id, it returns the string version of it and I can query the model using that value. However, I would like to leverage the dependency injection.
Are you using /api/v1/myroutes/organization.php as URL to request ? It supposed to be used as /api/v1/organizations/123 or /api/v1/organizations/the-organization-slug
Hi @aletopo, it's the file path in which I put the routes declaration related to the organization. I have different route files for different domains of the business. And as I mentioned, everything except for the dependency injection is working. This is the route called by postman or frontend app, /api/v1/admins/myroutes/organizations/first-organization
@Snapey Can you please let me know where to check the DB Queries? This is the route /api/v1/admins/myroutes/organizations/first-organization and first-organization is the slug.
@uminnkhantnaing simply try using ddd() function to examine all contextual information, like ddd($organiztion) in the route. If the model uses SoftDeletes or any other scoped query may be not be visible for any reason, and that could why always is getting an empty array. Check the model.