Skip to content

Instantly share code, notes, and snippets.

@IsraelOrtuno
Last active September 15, 2016 21:30
Show Gist options
  • Save IsraelOrtuno/f472929a7d77e9c97fd21727fa6e3632 to your computer and use it in GitHub Desktop.
Save IsraelOrtuno/f472929a7d77e9c97fd21727fa6e3632 to your computer and use it in GitHub Desktop.
<?php
FormBuilder::macro('openOrModel', function ($post, $put, $model = null) {
return ! $model
? \Form::open(['route' => $post, 'method' => 'post'])
: \Form::model($model, ['route' => $put, 'method' => 'put']);
});
// Use it like this:
//
// For PHP > 7
// {!! Form::openOrModel('user.store', 'user.update', $user ?? null !!}
//
// For PHP < 7
// {!! Form::openOrModel('user.store', 'user.update', isset($user) ? $user : null !!}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment