Kevin Jung happy thoughts!
Laravel 5.1 Form Model Binding

Ever since Laravel 5.1 launched, I've been missing the handy Form helper class. If you really wanted to, you can simply import the class hosted on Laravel Collective and carry on as before.

However, I've decided to go back to doing things the old fashioned way, and one feature I miss the most from before is the ability to do simple Form Model Binding.

Below is how I went about mimicking the Form Model Binding feature using the old() helper function.

Input

<input type="text" name="title" value="{{ (old('title') ? old('title') : $post->title) }}">

Select

<select name="category">
    <option value="general" {{ (old('category') === 'general' || $post->category === 'general' ? 'selected="selected"' : '') }}>General</option>
    <option value="tutorial" {{ (old('category') === 'tutorial' || $post->category === 'tutorial' ? 'selected="selected"' : '') }}>Tutorial</option>
    <option value="review" {{ (old('category') === 'review' || $post->category === 'review' ? 'selected="selected"' : '') }}>Review</option>
</select>

Radio

<input type="radio" name="gender" value="male" {{ (old('gender') === 'male' || $user->gender === 'male' ? 'checked="checked"' : '') }}>
<input type="radio" name="gender" value="female" {{ (old('gender') === 'female' || $user->gender === 'female' ? 'checked="checked"' : '') }}>

Checkbox

<input type="checkbox" name="pets" value="dog" {{ (old('pets') === 'dog' || $user->pets === 'dog' ? 'checked="checked"' : '') }}>
<input type="checkbox" name="pets" value="cat" {{ (old('pets') === 'cat' || $user->pets === 'cat' ? 'checked="checked"' : '') }}>
© 2015 Keivn Jung