RelationshipTransformer.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Transformer\Api;
  3. use Auth;
  4. use App\{
  5. FollowRequest,
  6. Profile
  7. };
  8. use League\Fractal;
  9. class RelationshipTransformer extends Fractal\TransformerAbstract
  10. {
  11. public function transform(Profile $profile)
  12. {
  13. $auth = Auth::check();
  14. if(!$auth) {
  15. return [];
  16. }
  17. $user = $auth ? Auth::user()->profile : false;
  18. $requested = false;
  19. if($user) {
  20. $requested = FollowRequest::whereFollowerId($user->id)
  21. ->whereFollowingId($profile->id)
  22. ->exists();
  23. }
  24. return [
  25. 'id' => (string) $profile->id,
  26. 'following' => $auth ? $user->follows($profile) : false,
  27. 'followed_by' => $auth ? $user->followedBy($profile) : false,
  28. 'blocking' => $auth ? $user->blockedIds()->contains($profile->id) : false,
  29. 'muting' => $auth ? $user->mutedIds()->contains($profile->id) : false,
  30. 'muting_notifications' => null,
  31. 'requested' => $requested,
  32. 'domain_blocking' => null,
  33. 'showing_reblogs' => null,
  34. 'endorsed' => false
  35. ];
  36. }
  37. }