public function upload()
 {
     $input = Input::all();
     $validation = Validator::make($input, Template::$rules);
     if ($validation->passes()) {
         $file = Input::file('image');
         // your file upload input field in the form should be named 'file'
         $css = Input::file('css');
         $destinationPath = app_path() . '/views/uploads/layouts';
         $csspath = public_path() . '/assets/css';
         $thumbdestination = public_path() . '/assets/thumb';
         $name = Input::get('name');
         $newname = str_replace(' ', '_', $name);
         $filename = $file->getClientOriginalName();
         //$extension =$file->getClientOriginalExtension();
         //if you need extension of the file
         $uploadSuccess = Input::file('image')->move($destinationPath, $filename);
         $extension = Input::file('thumbnail')->getClientOriginalExtension();
         $uploadthumbnail = Input::file('thumbnail')->move($thumbdestination, $newname . '.' . $extension);
         $uploadcss = Input::file('css')->move($csspath, $css . '.css');
         $input = Input::all();
         if ($uploadSuccess && $uploadthumbnail) {
             //return Response::json('success', 200); // or do a redirect with some message that file was uploaded
             $this->template->name = Input::get('name');
             $this->template->file = $filename;
             $this->template->css = $css;
             $this->template->save();
             $id = DB::getPdo()->lastInsertId();
             $thumb = new Image_thumbnail();
             $thumb->img = $newname . '.' . $extension;
             $thumb->title = $name;
             $thumb->t_id = $id;
             $thumb->save();
             return Redirect::route('templates.definefields', array('id' => $id));
         }
     }
     return Redirect::route('templates.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $this->image_thumbnail->find($id)->delete();
     return Redirect::route('image_thumbnails.index');
 }