Skip to content

Instantly share code, notes, and snippets.

@antonybudianto
Last active August 29, 2015 14:22
Show Gist options
  • Save antonybudianto/15ebef55b2232c725065 to your computer and use it in GitHub Desktop.
Save antonybudianto/15ebef55b2232c725065 to your computer and use it in GitHub Desktop.
Helper for form in L5.1
<?php
if(! function_exists('form_model')) {
function form_model($object = false)
{
return function($name) use ($object)
{
if(!$object) return old($name);
else return isset($object) ? $object->$name : old($name);
};
}
}
@antonybudianto
Copy link
Author

Register helper.php:

  • Add this new key to "autoload" key in your composer.json
   "files": ["app/Http/helpers.php"]
  • Then do
   php artisan clear-compiled

How to use:

  • In create method
   $form = form_model();
  • In edit method
   $form = form_model($model);
  • In create view
   <input value="{{ $form('fieldName') }}" type="text" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment