knitevision
knitevision

Reputation: 3143

Laravel 4 Form Select: apply a conditional class

{{ Form
.select('foo', {
    'foo': 'bar',
}) }}

I need to apply a class based on condition. For example I have an abstract error function that returns bool

How do I apply it like 'class' => 'error() ? 'my_class' : 'other_class' ?

I've seen this, and this <- no success

Upvotes: 1

Views: 347

Answers (1)

noodles_ftw
noodles_ftw

Reputation: 1313

In Laravel 4:

{{ Form::select('name', ['value' => 'Label', 'another-value => 'Label'], null, ['class' => error() ? 'class' : 'another-class']) }}

In Laravel 5:

{!! Form::select('name', ['value' => 'Label', 'another-value => 'Label'], null, ['class' => error() ? 'class' : 'another-class']) !!}

Upvotes: 2

Related Questions