mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-19 12:24:09 +00:00
60 lines
1.4 KiB
PHP
60 lines
1.4 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()->orderby('updated_at','desc');
|
|
}
|
|
|
|
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)->orderby('updated_at','desc')->get(),
|
|
"unread_message" =>Notification::Where([
|
|
["user_id",Auth::user()->id],
|
|
["is_read",0]
|
|
])->orderby('updated_at','desc')->get()
|
|
],200);
|
|
}
|
|
|
|
public function readNotification($notification_id){
|
|
$affected = DB::table('notifications')
|
|
->Where('id', $notification_id)
|
|
->update(array('is_read' => 1));
|
|
return response()->json("Read message", 200);
|
|
}
|
|
} |