first change
This commit is contained in:
49
Modules/CourseFinder/app/Services/CoopService.php
Normal file
49
Modules/CourseFinder/app/Services/CoopService.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user