Created
December 14, 2012 13:05
-
-
Save Sigmus/4285366 to your computer and use it in GitHub Desktop.
Laravel FormUtils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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