Exemplo n.º 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $banners = Banner::findOrFail($id);
     // Select Resource
     $pages = \App\Page::lists('title', 'id');
     return view('banners.edit')->with('banners', $banners)->with('pages', $pages);
 }
Exemplo n.º 2
0
 /**
  * Helper untuk melakukan Update new Data ke dalam database
  * @param int $id
  */
 private function updateData($id = 0)
 {
     $data = Banner::findOrFail($id);
     $file = Input::file('banner');
     $image_name = time() . "-banner-" . $file->getClientOriginalName();
     $file->move(public_path() . '/upload', $image_name);
     $data->image = $image_name;
     $data->save();
     return true;
 }
Exemplo n.º 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['judul_banner' => 'required|max:200', 'image' => 'mimes:jpeg,bmp,png']);
     $banner = Banner::findOrFail($id);
     $data['judul_banner'] = $request->judul_banner;
     if ($request->hasFile('image')) {
         $data['gambar_banner'] = $this->savePhoto($request->file('image'));
     }
     if ($banner->update($data)) {
         \Flash::success('Banner Berhasil Diupdate');
     } else {
         \Flash::info('Banner Gagal Diupdate');
     }
     return redirect('admin/banner');
 }
Exemplo n.º 4
0
 public function postDel(Request $request, $banner_id)
 {
     $res = ['response' => 'YES', 'status' => 0];
     $banner = Banner::findOrFail($banner_id);
     $img = $banner->Img_main()->first();
     if ($img) {
         $img->update(['img_active' => $img->img_active - 1 >= 0 ? $img->img_active - 1 : 0]);
     }
     $banner->delete();
     if (!Banner::find($banner_id)) {
         $res['status'] = 1;
     } else {
         $res['msgError'] = MSG_FA;
     }
     return response()->json($res);
 }
Exemplo n.º 5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Banner::findOrFail($id)->delete();
     return trans('banners.removed');
 }
Exemplo n.º 6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $banner = Banner::findOrFail($id);
     $thumbnail = $this->admin_content_path() . $this->slide_path . 'thumbnail_' . $banner->image;
     $photo = $this->admin_content_path() . $this->slide_path . 'photo_' . $banner->image;
     $preview = $this->admin_content_path() . $this->slide_path . 'preview_' . $banner->image;
     $slide = $this->app_content_path() . $this->slide_path . $banner->image;
     if (File::exists($thumbnail) && File::exists($photo) && File::exists($slide) && File::exists($preview)) {
         File::delete($thumbnail);
         File::delete($photo);
         File::delete($slide);
         File::delete($preview);
     }
     $banner->delete();
     return redirect()->route('Slides::index');
 }
Exemplo n.º 7
0
 /**
  * Destroy a model.
  *
  * @param $id
  * @return mixed
  */
 public function destroy($id)
 {
     $banner = Banner::findOrFail($id);
     $banner->delete();
     return redirect()->route('backend::banners_index')->with('success', 'Registro removido com sucesso.');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $banner = Banner::findOrFail($id);
     if (file_exists($banner->path)) {
         unlink($banner->path);
     }
     Banner::destroy($id);
     return redirect('/admin/banners');
 }
Exemplo n.º 9
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     $this->validate($request, ['title' => 'required', 'caption' => 'required']);
     $input = $request->all();
     $banner = Banner::findOrFail($id);
     $banner->fill($input);
     //dd($request->all());
     if ($request->hasFile('image')) {
         Image::destroy($banner->image_id);
         $image = $request->file('image');
         $image_name = $image->getClientOriginalName();
         $image->move(public_path() . '/images/banners/', $image_name);
         $newImage = Image::create(['image_name' => $image_name]);
         $banner->image_id = $newImage->id;
     }
     $banner->save();
     return redirect()->route('admin.banner.index');
 }
 public function edit(Request $request)
 {
     $bannerType = [Banner::BANNER_CODE => trans('admin_common.Javascript/HTML Banner'), Banner::BANNER_IMAGE => trans('admin_common.Image Banner')];
     $bannerPosition = [Banner::BANNER_POSITION_LIST => trans('admin_common.Ad List Position (728x90px)'), Banner::BANNER_POSITION_DETAIL => trans('admin_common.Ad Detail Right Position (300x250px)')];
     $id = 0;
     if (isset($request->id)) {
         $id = $request->id;
     }
     $modelData = new \stdClass();
     if ($id > 0) {
         try {
             $modelData = Banner::findOrFail($id);
         } catch (ModelNotFoundException $e) {
             session()->flash('message', trans('admin_common.Invalid Banner'));
             return redirect(url('admin/banner'));
         }
     }
     /**
      * form is submitted check values and save if needed
      */
     if ($request->isMethod('post')) {
         /**
          * validate data
          */
         $rules = ['banner_name' => 'required|max:255', 'banner_position' => 'required|integer|not_in:0', 'banner_type' => 'required|integer|not_in:0', 'banner_active_from' => 'required|max:255', 'banner_active_to' => 'required|max:255'];
         $validator = Validator::make($request->all(), $rules);
         /**
          * dynamic validation rules
          */
         $validator->sometimes(['banner_code'], 'required', function ($input) {
             if ($input->banner_type == Banner::BANNER_CODE) {
                 return true;
             }
             return false;
         });
         $validator->sometimes(['banner_link'], 'required|max:255', function ($input) {
             if ($input->banner_type == Banner::BANNER_IMAGE) {
                 return true;
             }
             return false;
         });
         $validator->sometimes(['banner_file'], 'required|mimes:jpeg,bmp,png,gif', function ($input) use($modelData) {
             if ($input->banner_type == Banner::BANNER_IMAGE && !isset($modelData->banner_id)) {
                 return true;
             }
             return false;
         });
         if ($validator->fails()) {
             $this->throwValidationException($request, $validator);
         }
         /**
          * get data from form
          */
         $data = $request->all();
         /**
          * check for uploaded banner
          */
         $banner_name = '';
         if ($request->hasFile('banner_file') && $request->file('banner_file')->isValid()) {
             $file = Input::file('banner_file');
             $banner_name = time() . '_banner.' . $file->getClientOriginalExtension();
             $file->move(public_path() . '/uf/banner', $banner_name);
             $data['banner_image'] = $banner_name;
         }
         /**
          * save or update
          */
         if (!isset($modelData->banner_id)) {
             Banner::create($data);
         } else {
             if (!empty($banner_name) && !empty($modelData->banner_image)) {
                 @unlink(public_path() . '/uf/banner/' . $modelData->banner_image);
             }
             $modelData->update($data);
         }
         /**
          * clear cache, set message, redirect to list
          */
         Cache::flush();
         session()->flash('message', trans('admin_common.Banner saved'));
         return redirect(url('admin/banner'));
     }
     return view('admin.banner.banner_edit', ['modelData' => $modelData, 'bannerType' => $bannerType, 'bannerPosition' => $bannerPosition]);
 }