Laravel trying to make skinny controller

Blackdaemon

New Member
im newbie in php and in mvc design pattern, my first framework is CI then i move from CI(just used it for 1 project then found this amazing laravel)i have read some of the articles about skinny controller, i kinda get the idea and after that im trying to make something like this in laravel
  • Example i want to make \[code\]FileHandler\[/code\] class, it will move the uploaded file(in this case i will upload image, after the \[code\]ImageValidator\[/code\] passes in the controller) and check if the file's upload already in the specified path :
in this case i want to upload image, so i make another class which is \[code\]ImageValidator\[/code\] that will validate the uploaded image:\[code\]class ImageValidator{ const IMG_RULES = 'required|image|max:150'; static public $validator; static public function getRules($fieldname) { $rules = array( $fieldname => ImageValidator::IMG_RULES ); return $rules; } static public function validate($fieldname) { $data = http://stackoverflow.com/questions/15852303/array( $fieldname => Input::file($fieldname) ); //validating the data using the rules static::$validator = Validator::make($data, static::getRules($fieldname)); //return TRUE if the the input file does not break any rule(s) return static::$validator->passes(); }}\[/code\]then this is the FileHandler\[code\]class FileHandler{ static public function move($fieldname, $path) { $file = Input::file($fieldname); //if the file's name already exists, it will change the uploaded file's name to a new one static::checkName($file, $path); //move the file to new path = ('public/imgs').. Input::upload($fieldname, $path, $file['name']); } static public function checkName(&$file, $path) { $count = ''; //set the path to the correct folder, in this case i want to upload img, so it will be imgs folder in public/imgs //get the full path, because Input::upload handles path differently then i need to modify it.. $path = path('public') . basename($path) . '/'; $separator = '_'; //while there's filename already, then do the count++ while(file_exists($path . $count . $separator . $file['name'])) { //convert the count to int and increments $count++; } //lets append the count , separator, with filename $img['name'] = $count . $separator . $file['name']; }}\[/code\]from controller:\[code\]//if the picture field(file input) doesn't pass the validatorif( ! ImageValidator::validate('picture')) { //redirect to the form with errors return Redirect::to('add/addImage')->with_errors(ImageValidator::$validator); }//the picture field(file input) passes the validator, move the picture to the public/imgs folder FileHandler::move('picture', 'public/imgs');\[/code\]and thats all i have made(well it works well when i test it in testing site), but i dont feel confident about it, i don't know what's / are wrong but i just feel something is not right..and im planning to make 1 more class \[code\]ImageHandler\[/code\] to handle image(resize using resizer bundle, CRUD image in DB, deleting image(s) in the specific directory), this class will use \[code\]ImageModel\[/code\](eloquent) to do CRUD but the \[code\]ImageHandler\[/code\] will simplify it more..do u guys think its a good idea to make one? or just make \[code\]ImageModel\[/code\] to handle CRUD, resize using bundle(some kind of plugin), deleting image(s) , etc..please guide me here, thanksSendy Halim
 
Back
Top