-
I'm just setting up a brand new project to play around with Actions v2, but whenever I POST to a route that points to an action, I get redirected to the homepage instead 🤔 My <?php
use Illuminate\Support\Facades\Route;
use App\Actions\Users\RegisterUser;
Route::post('users', RegisterUser::class); My <?php
namespace App\Actions\Users;
use Lorisleiva\Actions\Concerns\AsAction;
use Lorisleiva\Actions\ActionRequest;
use App\Models\User;
class RegisterUser
{
use AsAction;
public function rules(): array
{
return [
'name' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required|confirmed',
];
}
public function handle(array $userData): User
{
return User::create($userData);
}
public function asController(ActionRequest $request): User
{
return $this->handle($request->validated());
}
} I feel like I must be missing something obvious since I couldn't find any similar issues, but this is a really vanilla setup so I'm not sure what's going on here. I tested sending a simple JSON response in a closure-based route and that worked ok. Edit: FWIW this also works, so it seems to be something specific with using it as a controller: Route::post('users', function(Request $request) {
RegisterUser::run($request->all());
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok, I think this was just a weird issue with the HTTP client I was using to test the endpoint. I switched to using HTTPie and everything seems to work normally! |
Beta Was this translation helpful? Give feedback.
Ok, I think this was just a weird issue with the HTTP client I was using to test the endpoint. I switched to using HTTPie and everything seems to work normally!