Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

strmizo's avatar

In Form Submit Testing 'Undefined variable: errors'

I'm testing a form submit like this

     $data = [
            'start_date' => '12/07/2014',
            'end_date' => '19/09/2015',
            'name' => 'Tomorrow Land',
            'venue' => '16th street',
            'city' => 'LA',
            'address' => '12th AV Morocco, LA',
            'country_id' => \App\Country::where('name', $this->usa)->first()->id,
            'state_id' => 4,
            'latitude' => 18,
            'longitude' => -23
        ]; `

       ` $this->actingAs($admin)
            ->visit($this->festivalUrl('create'))
            ->submitForm('Create', $data )
            ->see('The cover image field is required.');

But when I run the test this error occurs

 exception 'ErrorException' with message 'Undefined variable: errors' in

I think the problem is from the view that has $errors variable which somehow is not filled.

0 likes
3 replies
strmizo's avatar

Yes, I have found that Phpunit can't execute the one line if statement with blade, so if you were writing like this

<div class="form-control ($errors->has('name')) ? 'has-error' : ' ' ">

than consider this to change this to normal if statement as

<div class="form-control @if(isset($errors) && $errors->has('name')) has-error @endif">
1 like
Jmac's avatar

Is this still true? Having the same problems with 5.3

Please or to participate in this conversation.