Files
exchange/app/Http/Controllers/NotificationController.php
T
2018-07-24 17:02:45 +08:00

58 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Notification;
use Illuminate\Support\Facades\DB;
use Auth;
class NotificationController extends Controller
{
public function index()
{
return Notification::all();
}
public function show(Notification $notification)
{
return $notification;
}
public function store(Request $request)
{
$notification = Notification::create($request->all());
return response()->json($notification, 201);
}
public function update(Request $request, Notification $notification)
{
$notification->update($request->all());
return response()->json($notification, 200);
}
public function delete(Notification $notification)
{
$notification->delete();
return response()->json(null, 204);
}
public function getUserMessage()
{
return response()->json([
"message" =>Notification::Where("user_id",Auth::user()->id)->get(),
"unread_message" =>Notification::Where([
["user_id",Auth::user()->id],
["is_read",0]
])->get()
],200);
}
public function readNotification(){
$affected = DB::table('notifications')->Where('user_id', Auth::user()->id)->update(array('is_read' => 1));
return response()->json("Read all message", 200);
}
}