misbar-backend/app/Services/ContactService.php
Moaz Dawalibi 44bff06c03 done
2024-07-03 11:28:16 +03:00

60 lines
1.4 KiB
PHP

<?php
namespace App\Services ;
use App\Models\Contact;
use App\Services\Base\BaseService;
use Carbon\Carbon;
class ContactService extends BaseService {
public function __construct()
{
parent::__construct(Contact::class);
}
public function create($data)
{
if (isset($data['image']))
{
$image = ImageService::upload_image($data['image'], 'contact');
} else {
$image = null;
}
$contact = Contact::create([
'image' => $image,
'title' => $data['title'],
'sub_title' => $data['sub_title'],
'description' => $data['description'],
'direction'=> $data['direction'] == true ?1 :0,
'is_have_button'=> $data['is_have_button'] == true ?1 :0
]);
$contact->save();
return [];
}
public function updateContact(int $id, $data)
{
$contact = Contact::find($id);
if (isset($data['image']))
{
$image = ImageService::update_image($data['image'], $contact->image, 'contact');
$data['image'] = $image;
}
return $this->update($id,$data);
}
public function delete(int $id)
{
$contact = Contact::find($id);
$contact->delete();
ImageService::delete_image($contact->image);
return [];
}
}