File manager - Edit - /var/www/html/pcadigital/api/app/Http/Services/FollowerService.php
Back
<?php namespace App\Http\Services; use App\Classes\BaseServiceResponse; use App\Models\Follower; use App\Models\Occurrence; use App\Repositories\FollowerRepository; use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\DB; class FollowerService extends BaseService { private FollowerRepository $followerRepository; public function __construct() { $this->followerRepository = new FollowerRepository(); } public function triggerFollower(array $data, array $user) : BaseServiceResponse { try { DB::beginTransaction(); $occurrence = Occurrence::find($data['occurrence_id']); $follower = $this->followerRepository->findUser($user['id']); if($follower == null) { $follower = $this->createFollower($user); } $result = $this->followerRepository->findOccurrenceByFollower($occurrence->id, $follower->id); if($result->count() > 0) { $occurrence->followers()->detach($follower->id); }else { $occurrence->followers()->attach($follower->id); } } catch (Exception $exception) { DB::rollBack(); return $this->error( [ 'message' => __('validation.validation_error'), 'data' => $exception->getMessage(), ], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } DB::commit(); return $this->success(null, JsonResponse::HTTP_OK); } public function getFollowerOccurrences(array $user, string $authUuid) { $follower = $this->followerRepository->findUser($authUuid); if($follower == null) { $follower = $this->createFollower($user); } $occurrences = $follower->occurrences()->paginate(10); return $occurrences; } private function createFollower(array $user) : Follower { $newFollower = new Follower(); $newFollower->name = $user['name']; $newFollower->auth_uuid = $user['id']; $newFollower->save(); return $newFollower; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings