Spamworldpro Mini Shell
Spamworldpro


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/ServiceBox/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mcoil.corals.io/app/Http/Controllers/Admin/ServiceBox/ServiceBoxController.php
<?php

namespace App\Http\Controllers\Admin\ServiceBox;

use App\Shop\ServiceBoxes\Repositories\Interfaces\ServiceBoxRepositoryInterface;
use App\Shop\ServiceBoxes\Repositories\ServiceBoxRepository;
use App\Shop\ServiceBoxes\ServiceBox;
use App\Shop\ServiceBoxes\Requests\UpdateServiceBoxRequest;
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 Illuminate\Support\Facades\File;

class ServiceBoxController extends Controller {
    use UploadableTrait;

    /**
     * @var ServiceBoxRepositoryInterface
     */
    private $serviceBoxRepo;

    /**
     * ServiceBoxController constructor.
     *
     * @param ServiceBoxRepositoryInterface $serviceBoxRepository
     * @param ServiceBox $serviceBox
     */
    public function __construct(
        ServiceBoxRepositoryInterface $serviceBoxRepository,
        ServiceBox $serviceBox
    ) {
        $this->serviceBoxRepo = $serviceBoxRepository;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        $list = $this->serviceBoxRepo->listServiceBoxes('id', 'asc');
        return view('admin.service-box.list', [
            'serviceBox' =>$list->all()
        ]);
    }


    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function edit(int $id) {
        $service = $this->serviceBoxRepo->findServiceBoxById($id);
        return view(
            'admin.service-box.edit',compact('service')
        );
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  UpdateServiceBoxRequest $request
     * @param  int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function update(UpdateServiceBoxRequest $request, int $id) {
        $currentData = $this->serviceBoxRepo->findServiceBoxById($id);
        $currentDataRepo = new ServiceBoxRepository($currentData);
        $data = $request->all();
        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'];
        }
        $newData = $currentDataRepo->updateServiceBox($data);
        return redirect()->route('admin.service.box.list')->with('message', 'Service box updated successfully.');
    }

    public function removeImage(Request $request,$id) {
        $service = $this->serviceBoxRepo->findServiceBoxById($id);
        if ($service) {
            //\Log::info(print_r($service,true));
            $image = $service->background_img;
            $destinationPath= public_path("img/images_uploaded");
            unlink($destinationPath.'/'.basename($service->background_img));
            ServiceBox::where('id',$service->id)->update(['background_img'=>'']);
            return 1; 
        }
        return 0;
    }
	
	 /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
	 
	function destroy(Request $request) {
		$id=$request->id;		
		$service = ServiceBox::where('id',$id)->first();
		// $image_path = app_path("public/img/images_uploaded/".);
        $destinationPath= public_path("img/images_uploaded");
        unlink($destinationPath.'/'.basename($service->background_img));
		ServiceBox::where('id',$id)->delete();
		return $id;	
	}
}

Spamworldpro Mini