Level 9
This was a me issue:
Get rid of $this->withoutExceptionHandling();
This code worked perfectly fine in Laravel 7. There must've been a change to $this-validate() in Laravel 8. How do I make sure I get a 422?
UniverseTest
public function a_universe_requires_a_name()
{
$this->withoutExceptionHandling();
$user = User::factory()->create();
$this->actingAs($user);
$universe = Universe::factory()->make(['user_id' => $user->id, 'name' => '']);
$response = $this->json('POST', '/api/universe/', $universe->toArray())
->assertStatus(422);
}
UniverseController
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'color' => 'required'
]);
$universe = Universe::create([
'name' => $request->input('name'),
'color' => $request->input('color'),
'user_id' => Auth::user()->id
]);
return new UniverseResource($universe);
}
Please or to participate in this conversation.