user101289
user101289

Reputation: 10422

Laravel 5.1 form

I'm using Laravel Collective to add back the Form helpers to Laravel 5.1. First, I'm not sure if there's a better tactic, but I didn't see anything describing this in the Laravel docs.

The issue is that the Laravel Collective docs don't address adding custom classes and properties to inputs. It does work to use the old style (though it's not documented), passing an array as the third parameter:

echo Form::text('username', '', ['class' => 'myclass', 'placeholder' => 'placeholder text']);

The issue is that when I use a Form model binding, the second "empty" value string means that the binding no longer works.

Is there a way to work around this?

Upvotes: 0

Views: 304

Answers (1)

Ted Avery
Ted Avery

Reputation: 5689

Leave the second parameter as null, not empty string.

echo Form::text('username', null, ['class' => 'myclass', 'placeholder' => 'placeholder text']);

The idea being that if your second parameter is null, that's the same as if you never passed a value at all, so you'll get the default behaviour (the form binding).

Upvotes: 1

Related Questions