55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Notification;
|
|
use App\Models\OnesignalAgent;
|
|
use App\Models\OnesignalUser;
|
|
use App\Traits\ApiResponser;
|
|
use Illuminate\Http\Request;
|
|
use Berkayk\OneSignal\OneSignalFacade;
|
|
use Mockery\Matcher\Not;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
use ApiResponser;
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
public function getNotifcations(Request $request)
|
|
{
|
|
$this->validate($request, [
|
|
'user_code' => 'required_without:agent_code',
|
|
'agent_code' => 'required_without:user_code'
|
|
]);
|
|
$notifications = [];
|
|
if (isset($request->user_code))
|
|
$notifications = Notification::where('user_code', $request->user_code)->orderBy('date' , 'DESC')->get();
|
|
elseif (isset($request->agent_code))
|
|
$notifications = Notification::where('agent_code', $request->agent_code)->orderBy('date' , 'DESC')->get();
|
|
|
|
foreach ($notifications as $notif) {
|
|
$notif->data = json_decode($notif->data);
|
|
}
|
|
|
|
return $this->successResponse($notifications);
|
|
}
|
|
|
|
public function readNotification($id_notif){
|
|
$notif = Notification::findOrFail($id_notif);
|
|
$notif->read = true;
|
|
$notif->save();
|
|
return $this->successResponse('Success');
|
|
}
|
|
|
|
|
|
}
|