![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mcoil.corals.io/app/Http/Controllers/Admin/Banners/ |
<?php namespace App\Http\Controllers\Admin\Banners; use Illuminate\Support\Facades\Storage; use App\Shop\Banners\Repositories\Interfaces\BannerRepositoryInterface; use App\Shop\Banners\Repositories\BannerRepository; use App\Shop\Banners\Banner; use App\Shop\Banners\Requests\CreateBannerRequest; use App\Shop\Banners\Requests\UpdateBannerRequest; use App\Http\Controllers\Controller; use App\Shop\Tools\UploadableTrait; use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; use App\Helper\Helper; class BannerController extends Controller { use UploadableTrait; /** * @var BannerRepositoryInterface */ private $bannerRepo; /** * BannerController constructor. * * @param BannerRepositoryInterface $bannerRepository * @param Banner $banner */ public function __construct( BannerRepositoryInterface $bannerRepository, Banner $banner ) { $this->bannerRepo = $bannerRepository; } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $list = $this->bannerRepo->listBanners('id', 'asc'); return view('admin.banner.list', ['banners' => $list->all()]); } /** * Show the form for editing the specified resource. * * @param int $id * * @return \Illuminate\Http\Response */ public function create() { return view('admin.banner.create'); } /** * Update the specified resource in storage. * * @param CreateBannerRequest $request * @param int $id * * @return \Illuminate\Http\Response */ public function store(Request $request) { if ($request->hasFile('background_img')) { $filename = $this->bannerRepo->saveBackgroundImage($request->file('background_img')); } else { $filename = $request->input('background_img_mobile'); } if ($request->hasFile('background_img_mobile')) { $filename1 = $this->bannerRepo->saveBackgroundImage($request->file('background_img_mobile')); } else { $filename1 = $request->input('background_img_mobile'); } Banner::create([ 'title' => $request->input("title"), 'sub_title' => $request->input("sub_title"), 'button_text' => $request->input("button_text"), 'link_button' => $request->input("link_button"), 'button_text2' => $request->input("button_text"), 'button_link2' => $request->input("button_link2"), 'video_embed' => basename($request->input("video_embed")), 'background_img' => $filename, 'background_img_mobile' => $filename1, 'content' => $request->input("content"), ]); $list = $this->bannerRepo->listBanners('id', 'asc'); return redirect()->route('admin.banner.list')->with('message', 'Banner added successfully.'); } /** * Show the form for editing the specified resource. * * @param int $id * * @return \Illuminate\Http\Response */ public function edit(int $id) { $banner = $this->bannerRepo->findBannerById($id); return view('admin.banner.edit',compact('banner')); } /** * Update the specified resource in storage. * * @param UpdateBannerRequest $request * @param int $id * * @return \Illuminate\Http\Response */ public function update(UpdateBannerRequest $request, int $id) { $currentData = $this->bannerRepo->findBannerById($id); $currentDataRepo = new BannerRepository($currentData); $data = $request->all(); $embed_video = [ 'video_embed' => basename($request->video_embed) ]; if ($request->hasFile('background_img')) { $data['background_img'] = $currentDataRepo->saveBackgroundImage($request->file('background_img')); if (!empty($data['background_img'])) { $currentDataRepo->deleteBackgroundImage(); } } else { $data['background_img'] = $currentData->getOriginal()['background_img']; } if ($request->hasFile('background_img_mobile')) { $data['background_img_mobile'] = $currentDataRepo->saveBackgroundImageMobile($request->file('background_img_mobile')); if (!empty($data['background_img_mobile'])) { $currentDataRepo->deleteBackgroundImageMobile(); } } else { $data['background_img_mobile'] = $currentData->getOriginal()['background_img_mobile']; } $newData = $currentDataRepo->updateBanner($data); $newData = $currentDataRepo->updateBanner($embed_video); return redirect()->route('admin.banner.list')->with('message', 'Banner updated successfully.'); } public function removeImage(Request $request, $id){ $banner = $this->bannerRepo->findBannerById($id); if ($banner) { //\Log::info(print_r($banner,true)); $image = $banner->background_img; $destinationPath= public_path("img/images_uploaded"); unlink($destinationPath.'/'.basename($banner->background_img)); Banner::where('id', $banner->id)->update(['background_img'=>'']); return 1; } return 0; } public function removeMobileImage(Request $request, $id){ $banner = $this->bannerRepo->findBannerById($id); if ($banner) { //\Log::info(print_r($banner,true)); $image = $banner->background_img_mobile; $destinationPath= public_path("img/images_uploaded"); unlink($destinationPath.'/'.basename($banner->background_img_mobile)); Banner::where('id', $banner->id)->update(['background_img_mobile'=>'']); return 1; } return 0; } /** * Show the form for editing the specified resource. * * @param int $id * * @return \Illuminate\Http\Response */ public function destroy(Request $request, int $id) { $id = $request->id; $currentData = $this->bannerRepo->findBannerById($id); $currentDataRepo = new BannerRepository($currentData); $currentDataRepo->deleteBanner(); return redirect()->back(); } }