Answer the question
In order to leave comments, you need to log in
Laravel ui:auth - how to return json?
I'm trying to build a spa application using Laravel + vue
I'm writing a test, I'm doing in the test:
public function a_guest_can_create_an_account()
{
$response = $this->post('/register', [
'name' => 'Test',
'email' => '[email protected]',
'password' => '1234567890',
]);
$response->assertStatus(201);
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
if ($response = $this->registered($request, $user)) {
return $response;
}
return $request->wantsJson()
? new Response('', 201)
: redirect($this->redirectPath());
}
return $request->wantsJson()
? new Response('', 201)
: redirect($this->redirectPath());
worked the line "? new Response('', 201)" instead of the line " redirect($this->redirectPath());" and I got the desired 201 status in the test?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question