简体   繁体   中英

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM