Support the ongoing development of Laravel.io →
posted 11 years ago
Validation

I have a form to create a new category :

{{ Form::open(['route' => ['category.store'], 'method' => 'POST']) }}
	...
	
	{{ Form::label('is_parent') }}
	{{ Form::checkbox('is_parent') }}
	
	{{ Form::label('parent_id') }}
	{{ Form::select('parent_id', $categories) }}
	
	{{ Form::submit('Create') }}

{{ Form::close() }}

The $categories array contains ['' => 'Not Selected] as first record followed by main categories.

My validation rules :

...
'parent_id' =>  'required_without:is_parent|exists:categories,id,parent_id,null'

Now, when I hit a request with the is_parent selected, it should not check for exists rule. But I still get an error saying : The selected parent id is invalid. Also, the same is the case with unchecked.

Any idea what am I missing ?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mcraz mcraz Joined 12 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.