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