pearlkrishn/lumen-request-validate

Dingo incompatible?

Dach0 opened this issue · 3 comments

Dach0 commented

Hi there. I have installed this package in Lumen 5.8.4 in witch I'm using Dingo package for api routing. It seems those two cannot work together or I'm doing something wrong.
I've set up everything and validation logic: rules and messages works fine when I define them in class(through postmen I receive "this field is required" etc ), but when everything is fine, when all fields are OK (from frontend side) I got this message

{
"message": "Method App\Http\Requests\StoreVehicleRequest::validate does not exist.",
"status_code": 500,
"debug": {
"line": 102,
"file": "E:\Damjan\Programiranje\PHP\Laravel\Lumen\automoto-lumen\vendor\illuminate\support\Traits\Macroable.php",
"class": "BadMethodCallException",
"trace": [
"#0 E:\Damjan\Programiranje\PHP\Laravel\Lumen\automoto-lumen\vendor\dingo\api\src\Provider\LumenServiceProvider.php(58): Illuminate\Http\Request->__call('validate', Array)"...

This is my app.php
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Dingo\Api\Provider\LumenServiceProvider::class);
$app->register(Pearl\RequestValidate\RequestServiceProvider::class);
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);

And as I can see from trace, RequestServiceProvder is never called. It looks like Dingo is overriding it? Any thoughts?

I've tried to reorder things but still the same problem.

Thanks in advanced.

Dach0 commented

Ok, as I ran through the code, I saw that RequestServiceProvider is called and it's working as it should be, but I believe this could be the issue...
https://github.com/dingo/api/pull/1654/files
when I change it as described it's working fine. So, if you also find this as a solution we can close the issue.

Yes, Dingo package overriding it. You can use Dingo package for validating request data by extending Dingo\Api\Http\FormRequest class instead of Pearl\RequestValidate\FormRequest.

Dach0 commented

This is exactly what I've just done. And it's working :) I have made workaround before this, I've copied LumenServiceProvider in my provider (what could possibly made some other errors with Dingo in the future but I'm not sure), made a changes as described in above link and registered it in bootstrap/app.php, but this is just a nicer solution.

Thanks @pearlkrishn