- 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:
58
app/Services/FilterService.php
Normal file
58
app/Services/FilterService.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Repositories\Filter;
|
||||
|
||||
class FilterService
|
||||
{
|
||||
private $filterRepository;
|
||||
|
||||
public function __construct(Filter $filterRepository)
|
||||
{
|
||||
$this->filterRepository = $filterRepository;
|
||||
}
|
||||
|
||||
public function save(array $data)
|
||||
{
|
||||
if (isset($data['id'])) {
|
||||
$filter = $this->filterRepository->findOrFail($data['id']);
|
||||
$filter->update($data);
|
||||
} else {
|
||||
$filter = $this->filterRepository->create($data);
|
||||
}
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$filter = $this->filterRepository->findOrFail($id);
|
||||
$filter->delete();
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
return $this->filterRepository->findOrFail($id);
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->filterRepository->all();
|
||||
}
|
||||
|
||||
public function with(array $children)
|
||||
{
|
||||
return $this->filterRepository->with($children)->get();
|
||||
}
|
||||
|
||||
public function withCount(array $children)
|
||||
{
|
||||
return $this->filterRepository->withCount($children)->get();
|
||||
}
|
||||
|
||||
public function getOneWith($id, array $children)
|
||||
{
|
||||
return $this->filterRepository->with($children)->findOrFail($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user