Update NotificationTransformer

This commit is contained in:
Daniel Supernault 2019-05-26 23:04:43 -06:00
parent 1c900a4ba4
commit 95bcb50329
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -2,7 +2,10 @@
namespace App\Transformer\Api;
use App\Notification;
use App\{
Notification,
Status
};
use League\Fractal;
class NotificationTransformer extends Fractal\TransformerAbstract
@ -10,6 +13,7 @@ class NotificationTransformer extends Fractal\TransformerAbstract
protected $defaultIncludes = [
'account',
'status',
'relationship'
];
public function transform(Notification $notification)
@ -30,9 +34,14 @@ class NotificationTransformer extends Fractal\TransformerAbstract
public function includeStatus(Notification $notification)
{
$item = $notification->item;
if(is_object($item) && get_class($item) === 'App\Status') {
return $this->item($item, new StatusTransformer());
$item = $notification;
if($item->item_id && $item->item_type == 'App\Status') {
$status = Status::with('media')->find($item->item_id);
if($status) {
return $this->item($status, new StatusTransformer());
} else {
return null;
}
} else {
return null;
}
@ -50,4 +59,9 @@ class NotificationTransformer extends Fractal\TransformerAbstract
];
return $verbs[$verb];
}
public function includeRelationship(Notification $notification)
{
return $this->item($notification->actor, new RelationshipTransformer());
}
}