How can I make my select element a required select element?
What I want in HTML :
What I have at the moment in blade:
{!! Form::select('someid', [null => 'Please Select'] + $somelist, ['required']) !!}
Thanks
You want the 4th argument to select - 'options'
public function select($name, $list = [], $selected = null, $options = [])
{!! Form::select('someid', [null => 'Please Select'] + $somelist, null, ['required']) !!}
According to Laravel API, you have missed the 4th parameter:
string select(
string $name,
array $list = array(),
string $selected = null,
array $options = array()
)
/*
Parameters:
string $name
array $list
string $selected
array $options
Return Value:
string
*/
{!! Form::select('someid', [null => 'Please Select'] + $somelist, null, ['required']) !!}
In Laravel you don't need to require a field value. For this purpose you will use a request where you can set your rules:
public function rules()
{
return [
'name' => 'required',
];
}
If the validation fails than you can not post your form.
It is bad practice to rely on client-side validation.