laravel-learn-bbs/app/Http/Controllers/Api/NotificationsController.php

33 lines
716 B
PHP
Raw Normal View History

2018-06-11 14:27:53 +00:00
<?php
namespace App\Http\Controllers\Api;
use App\Transformers\NotificationTransformer;
class NotificationsController extends Controller
{
public function index()
{
$user = $this->user();
$notifications = $user->notifications()->paginate(20);
return $this->response->paginator($notifications, new NotificationTransformer());
}
/**
* @return mixed
* @throws \ErrorException
*/
public function stats()
{
return $this->response->array([
'unread_count' => $this->user()->notification_count,
]);
}
public function read()
{
$this->user()->markAsRead();
return $this->response->noContent();
}
}