lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 124 forks source link

Route resource redirecting to home #169

Closed rafa-acioly closed 2 years ago

rafa-acioly commented 2 years ago

After registering my action in my routes:

Route::prefix('products')->group(function () {
    Route::put('/', UpsertProduct::class);
    Route::get('/', function () {
        return "ok";
    });
});

The PUT endpoint always redirect to the home page. I've added the method asController like this:

public function asController(Request $request): JsonResponse
{
    return response()->json(["ok"]);
}

What am I missing? The package version works on Laravel 9?

Details:


{
    "php": "^8.0.2",
    "laravel/framework": "^9.0",
    "lorisleiva/laravel-actions": "^2.3"
}
rafa-acioly commented 2 years ago

I've notice that the validations was not passing and for that reason the redirect occurs.

Now, how can I send a json response with the errors that occur?

Wulfheart commented 2 years ago

Maybe this helps? https://laravelactions.com/2.x/as-controller.html#jsonresponse

Wulfheart commented 2 years ago

@rafa-acioly Maybe send it with a header that it expects JSON?

rafa-acioly commented 2 years ago

adding the Accept: application/json header worked, thanks!