Ejemplo n.º 1
0
 public function create($data)
 {
     return HomeBanner::create($data);
 }
Ejemplo n.º 2
0
 /**
  * Method to add a new home_banner
  *
  * @return string
  */
 public function batchDelete($ids)
 {
     $response = HomeBanner::whereIn('id', $ids)->delete();
     return $response;
 }
Ejemplo n.º 3
0
 public function update($id)
 {
     $input = Input::all();
     $rules = array('image' => 'image');
     $niceNames = array('image' => 'Home Banner');
     $validator = Validator::make($input, $rules);
     $validator->setAttributeNames($niceNames);
     if ($validator->fails()) {
         return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]);
     } else {
         $HomeBanner = HomeBanner::find($id);
         if (Input::has('show')) {
             $HomeBanner->show = Input::get('show');
         }
         if (Input::has('ordering')) {
             $HomeBanner->ordering = Input::get('ordering');
         }
         if (Input::has('status')) {
             $HomeBanner->status = Input::get('status');
         }
         if (Input::has('link_path')) {
             $HomeBanner->link_path = Input::get('link_path');
         }
         if (Input::has('title')) {
             $HomeBanner->title = Input::get('title');
         }
         if (Input::hasfile('image')) {
             $file = Input::file('image');
             $destinationPath = 'uploads/banners/';
             $filename = $file->getClientOriginalName();
             Input::file('image')->move($destinationPath, $filename);
             $ext = substr($filename, strrpos($filename, "."));
             $newFileName = basename($filename, $ext) . "_" . $HomeBanner->id . "_" . date("Ymdhis") . $ext;
             rename($destinationPath . $filename, $destinationPath . $newFileName);
             HomeBanner::where('id', $HomeBanner->id)->update(['image_path' => $destinationPath . $newFileName]);
         }
         $HomeBanner->save();
         if (Input::hasfile('image')) {
             return Response::json(['success' => true, 'message' => 'Home Banner has been updated!', 'file' => asset($destinationPath . $newFileName)]);
         } else {
             return Response::json(['success' => true, 'message' => 'Home Banner has been updated!']);
         }
     }
 }