56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services ;
|
|
use App\Models\Works;
|
|
use App\Services\Base\BaseService;
|
|
class WorksService extends BaseService {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct(Works::class);
|
|
}
|
|
public function create($data)
|
|
{
|
|
if (isset($data['image']))
|
|
{
|
|
$image = ImageService::upload_image($data['image'], 'works');
|
|
} else {
|
|
$image = null;
|
|
}
|
|
|
|
$works = Works::create([
|
|
'image' => $image,
|
|
]);
|
|
$works->save();
|
|
|
|
return [];
|
|
}
|
|
|
|
public function updateWorks(int $id, $data)
|
|
{
|
|
|
|
$works = Works::find($id);
|
|
|
|
if (isset($data['image']))
|
|
{
|
|
$image = ImageService::update_image($data['image'], $works->image, 'works');
|
|
$data['image'] = $image;
|
|
|
|
}
|
|
return $this->update($id,$data);
|
|
|
|
}
|
|
public function delete(int $id)
|
|
{
|
|
|
|
$works = Works::find($id);
|
|
|
|
$works->delete();
|
|
|
|
ImageService::delete_image($works->image);
|
|
|
|
return [];
|
|
}
|
|
|
|
}
|