Skip to content

Commit

Permalink
消息通知列表
Browse files Browse the repository at this point in the history
  • Loading branch information
liyu001989 committed Aug 7, 2020
1 parent 2e52678 commit 321ed6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/Http/Controllers/Api/NotificationsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Resources\NotificationResource;

class NotificationsController extends Controller
{
public function index(Request $request)
{
$notifications = $request->user()->notifications()->paginate();

return NotificationResource::collection($notifications);
}
}
19 changes: 19 additions & 0 deletions app/Http/Resources/NotificationResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class NotificationResource extends JsonResource
{
public function toArray($request)
{
return[
'id' => $this->id,
'type' => $this->type,
'data' => $this->data,
'read_at' => (string) $this->read_at ?: null,
'created_at' => (string) $this->created_at,
];
}
}
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
// 删除回复
Route::delete('topics/{topic}/replies/{reply}', 'RepliesController@destroy')
->name('topics.replies.destroy');
// 通知列表
Route::get('notifications', 'NotificationsController@index')
->name('notifications.index');
});
});
});

0 comments on commit 321ed6c

Please sign in to comment.