![]() 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/Shop/ServiceBoxes/Repositories/ |
<?php namespace App\Shop\ServiceBoxes\Repositories; use App\Shop\ServiceBoxes\ServiceBox; use Illuminate\Support\Collection; use Illuminate\Support\Str; use Jsdecena\Baserepo\BaseRepository; use Illuminate\Database\QueryException; use Illuminate\Database\Eloquent\ModelNotFoundException; use App\Shop\ServiceBoxes\Repositories\Interfaces\ServiceBoxRepositoryInterface; use App\Shop\Tools\UploadableTrait; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; class ServiceBoxRepository extends BaseRepository implements ServiceBoxRepositoryInterface { /** * ServiceBoxRepository constructor. * * @param ServiceBox $dummy */ public function __construct(ServiceBox $dummy) { parent::__construct($dummy); $this->model = $dummy; } /** * List all the ServiceBoxes * * @param string $order * @param string $sort * @param array $except * @return \Illuminate\Support\Collection */ public function listServiceBoxes(string $order = 'id', string $sort = 'desc', $except = []) : Collection { return $this->model->orderBy($order, $sort)->get()->except($except); } /** * Create ServiceBox * * @param array $params * * @return ServiceBox * @throws InvalidArgumentException */ public function createServiceBox(array $params) : ServiceBox { try { return ServiceBox::create($params); } catch (QueryException $e) { throw new InvalidArgumentException($e->getMessage()); } } /** * Update the dummy * * @param array $params * @return ServiceBox */ public function updateServiceBox(array $params) : ServiceBox { $dummy = $this->findServiceBoxById($this->model->id); $dummy->update($params); return $dummy; } /** * @param int $id * * @return ServiceBox * @throws ModelNotFoundException */ public function findServiceBoxById(int $id) : ServiceBox { try { return $this->findOneOrFail($id); } catch (ModelNotFoundException $e) { throw new ModelNotFoundException($e->getMessage()); } } /** * Delete a dummy * * @return bool */ public function deleteServiceBox() : bool { return $this->model->delete(); } /** * @param UploadedFile $file * @return string */ public function saveBackgroundImage(UploadedFile $file) : string { $filename = Str::random(25).'.'.$file->getClientOriginalExtension(); Storage::disk('images_uploaded')->put($filename, file_get_contents($file->getRealPath())); return $filename; } /** * Delete file * @return bool */ public function deleteBackgroundImage() : bool { return \Storage::disk('images_uploaded')->delete($this->model->getOriginal()['background_img']); } }