Trying to create the documentation with the command
php artisan api:generate --routePrefix="api/v2/*"
this error is generated:
```
[ErrorException]
strpos() expects parameter 1 to be string, object given
In `laravel.log` file, I find:
`local.ERROR: strpos() expects parameter 1 to be string, object given {"exception":"[object] (ErrorException(code: 0): strpos() expects parameter 1 to be string, object given at /vendor/mpociot/laravel-apidoc-generator/src/Mpociot/ApiDoc/Generators/AbstractGenerator.php:475)
`
The Request does not have a string in the validation rules, but a custom Rule:
public function rules()
{
return [
'firstname' => 'required|string|between:3,50',
'lastname' => 'required|string|between:3,50',
'gender' => 'required',
'birthday' => ['required', 'date', new AgeRating],
];
}
```
How can I fix this?
I'm getting this error too.
Late to the party - but because it's expecting a string, maybe you can add a function to the custom Rule:
public function __toString()
{
return 'Name of Rule';
}
Hope it will fix your problem :)
Adding a __toString() method solves this problem, but I still think that the generator should ignore Rule classes that do not have such a method.
Hello, where I have to add this method ? @KuenzelIT
You have to add this method to your custom Rule class.
@kew1n8or Does it actually matter what I return in the toString method? Will it affect my application that use this Rule class?
Nope. Just make sure to return a string - that's what the generator expects :)
We should make a note of this in the documentation, I think. We can also add a sensible default by using the result of message() . On the map for version 3.0.
Updated doc in #342
Most helpful comment
Late to the party - but because it's expecting a string, maybe you can add a function to the custom Rule:
Hope it will fix your problem :)