54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services ;
|
|
use App\Models\SocialMedia;
|
|
use App\Services\Base\BaseService;
|
|
use Carbon\Carbon;
|
|
class SocialMediaService extends BaseService {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct(SocialMedia::class);
|
|
}
|
|
public function create($data)
|
|
{
|
|
|
|
$image = ImageService::upload_image($data['image'], 'social_media');
|
|
|
|
$social_media = SocialMedia::create([
|
|
'image' => $image,
|
|
'link' => $data['link'],
|
|
'is_active'=> $data['is_active'] == true ?1 :0
|
|
]);
|
|
$social_media->save();
|
|
|
|
return [];
|
|
}
|
|
|
|
public function updateSocialMedia(int $id, $data)
|
|
{
|
|
$social_media = SocialMedia::find($id);
|
|
|
|
if (isset($data['image']))
|
|
{
|
|
$image = ImageService::update_image($data['image'], $social_media->image, 'social_media');
|
|
$data['image'] = $image;
|
|
|
|
}
|
|
return $this->update($id,$data);
|
|
|
|
}
|
|
public function delete(int $id)
|
|
{
|
|
|
|
$social_media = SocialMedia::find($id);
|
|
|
|
$social_media->delete();
|
|
|
|
ImageService::delete_image($social_media->image);
|
|
|
|
return [];
|
|
}
|
|
|
|
}
|