-
-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@urlParam as slug which is not primary key #275
Comments
Where did you do the binding? |
I try different options and with binding, I have this config
<?php
public function show(Author $author)
{
try {
$author = AuthorResource::make($author);
return $author;
} catch (\Throwable $th) {
return response()->json(['failed' => 'No result for '.$author], 404);
}
}
<?php
// ...
/**
* Retrieve the model for a bound value.
*
* @param mixed $value
* @param string|null $field
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function resolveRouteBinding($value, $field = null)
{
return $this->where('slug', $value)->with('media')->withCount('books')->firstOrFail();
} |
Had a similar issue. As a workaround, I managed to generate the docs correctly by specifying the parameter twice: as ID and as the name of the binding ("author" in your case). EDIT: This second image shows the correct ID in the request, and the response generated. The id is not the same , as it shows the remaining items in the cart: Hope this helps. |
Hmm. Right now, the strategy works with inline bindings ( |
(Alternatively, if you don't want to disable that strategy entirely, you can edit the relevant YAML file in |
Just pinning this here for later reference: https://laravel.com/docs/8.x/routing#customizing-the-resolution-logic |
My workaround for kinda this issue was like this - Made a strategy
In the strategies i place it in the metadata
So what happens is the conversion to {id} is skipped. |
i use the
|
What happened?
Author
with a primary key asint
id
but I bind my routes withstring
slug
to find details of model.In
routes/api.php
, the URL parameter is calledauthor
.In
app/Http/Controllers/Api:AuthorController.php
, I have to override with@urlParam
forid
instead ofauthor
, because scribe findid
as primary key I suppose. It's not really a problem, except that seeing a parameter indicated asid
can lead to errors but I don't know how to override the parameter name. I give an example for request to have correct response.php artisan scribe:generate
, I've this result.Example request
with"http://localhost:8000/api/authors/lovecraft-howard-phillips"
but for the response, scribe try to find result withid
1
as parameter:"failed": "No result for 1"
.My environment:
My Scribe config
The text was updated successfully, but these errors were encountered: