- Complete GGZ Ecademy Laravel backend application - RESTful API for learning products, members, filters - Authentication and authorization system - Database migrations and seeders - Custom CRUD generator commands - Email notification system - Integration with frontend applications
This commit is contained in:
53
app/Services/ContactService.php
Normal file
53
app/Services/ContactService.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Repositories\Contact;
|
||||
|
||||
class ContactService
|
||||
{
|
||||
private $contactRepository;
|
||||
|
||||
public function __construct(Contact $contactRepository)
|
||||
{
|
||||
$this->contactRepository = $contactRepository;
|
||||
}
|
||||
|
||||
public function save(array $data)
|
||||
{
|
||||
if (isset($data['id'])) {
|
||||
$contact = $this->contactRepository->findOrFail($data['id']);
|
||||
$contact->update($data);
|
||||
} else {
|
||||
$contact = $this->contactRepository->create($data);
|
||||
}
|
||||
|
||||
return $contact;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$contact = $this->contactRepository->findOrFail($id);
|
||||
$contact->delete();
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
return $this->contactRepository->findOrFail($id);
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->contactRepository->all();
|
||||
}
|
||||
|
||||
public function with(array $children)
|
||||
{
|
||||
return $this->contactRepository->with($children)->get();
|
||||
}
|
||||
|
||||
public function getOneWith($id, array $children)
|
||||
{
|
||||
return $this->contactRepository->with($children)->findOrFail($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user