first change
This commit is contained in:
67
Modules/Employee/app/Services/DesignationService.php
Normal file
67
Modules/Employee/app/Services/DesignationService.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Employee\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Employee\Models\Designation;
|
||||
|
||||
class DesignationService
|
||||
{
|
||||
|
||||
public function getAllDesignations(Request $request, callable $query = null, $paginate = false, $limit = 10)
|
||||
{
|
||||
$baseQuery = Designation::query();
|
||||
|
||||
if (is_callable($query)) {
|
||||
$query($baseQuery);
|
||||
}
|
||||
|
||||
if ($paginate) {
|
||||
return $baseQuery->paginate($limit);
|
||||
}
|
||||
|
||||
return $baseQuery->get();
|
||||
}
|
||||
|
||||
public function storeDesignation(array $designationData): Designation
|
||||
{
|
||||
return DB::transaction(function () use ($designationData) {
|
||||
$designation = Designation::create($designationData);
|
||||
|
||||
return $designation;
|
||||
});
|
||||
}
|
||||
|
||||
public function getDesignationById(int $id)
|
||||
{
|
||||
return Designation::findOrFail($id);
|
||||
}
|
||||
|
||||
public function updateDesignation(int $id, array $designationData)
|
||||
{
|
||||
$designation = $this->getDesignationById($id);
|
||||
|
||||
return DB::transaction(function () use ($designation, $designationData) {
|
||||
$designation->update($designationData);
|
||||
return $designation;
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteDesignation(int $id)
|
||||
{
|
||||
return DB::transaction(function () use ($id) {
|
||||
$designation = $this->getDesignationById($id);
|
||||
$designation->delete();
|
||||
return $designation;
|
||||
});
|
||||
}
|
||||
|
||||
public function pluck(callable $query = null)
|
||||
{
|
||||
$baseQuery = Designation::query();
|
||||
if (is_callable($query)) {
|
||||
$query($baseQuery);
|
||||
}
|
||||
return $baseQuery->pluck('title', 'id');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user