50 lines
1.0 KiB
PHP
50 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\CourseFinder\Services;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\CourseFinder\Models\Coop;
|
|
|
|
class CoopService
|
|
{
|
|
|
|
public function getAllCategories()
|
|
{
|
|
$query = Coop::query();
|
|
return $query->get();
|
|
}
|
|
|
|
public function storeCoop(array $coopData): Coop
|
|
{
|
|
return DB::transaction(function () use ($coopData) {
|
|
$coop = Coop::create($coopData);
|
|
|
|
return $coop;
|
|
});
|
|
}
|
|
|
|
public function getCoopById(int $id)
|
|
{
|
|
return Coop::findOrFail($id);
|
|
}
|
|
|
|
public function updateCoop(int $id, array $coopData)
|
|
{
|
|
$coop = $this->getCoopById($id);
|
|
|
|
return DB::transaction(function () use ($coop, $coopData) {
|
|
$coop->update($coopData);
|
|
return $coop;
|
|
});
|
|
}
|
|
|
|
public function deleteCoop(int $id)
|
|
{
|
|
return DB::transaction(function () use ($id) {
|
|
$coop = $this->getCoopById($id);
|
|
$coop->delete();
|
|
return true;
|
|
});
|
|
}
|
|
}
|