| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Services;
- use App\Models\{{modelName}};
- use Illuminate\Database\Eloquent\Collection;
- class {{modelName}}Service
- {
- public function getAll(): Collection
- {
- return {{modelName}}::query()
- ->orderBy('created_at', 'desc')
- ->get();
- }
- public function findById(int $id): ?{{modelName}}
- {
- return {{modelName}}::find($id);
- }
- public function create(array $data): {{modelName}}
- {
- return {{modelName}}::create($data);
- }
- public function update(int $id, array $data): ?{{modelName}}
- {
- $model = $this->findById($id);
- if (!$model) {
- return null;
- }
- $model->update($data);
- return $model->fresh();
- }
- public function delete(int $id): bool
- {
- $model = $this->findById($id);
- if (!$model) {
- return false;
- }
- return $model->delete();
- }
- // Add custom business logic methods here
- }
|