Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created December 14, 2012 13:05
Show Gist options
  • Save Sigmus/4285366 to your computer and use it in GitHub Desktop.
Save Sigmus/4285366 to your computer and use it in GitHub Desktop.
Laravel FormUtils
<?php
class FormUtils {
/**
* Manipulates object using current input.
*
* @param Eloquent $eloquent
* @return Eloquent
*/
public static function processInput($eloquent, $handleUpload)
{
$eloquent->fill(Input::all())->save();
if (isset($eloquent->files))
{
foreach ($eloquent->files as $name)
{
$handleUpload($name, $eloquent);
}
}
return $eloquent;
}
/**
* Injects specific form data into the provided input.
*
* @param array $data
* @return array
*/
public static function populateForm($data)
{
$eloquent = $data['eloquent'];
if (method_exists($eloquent, 'populateForm'))
{
$data = array_merge($data, $eloquent->populateForm());
}
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment