You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							38 lines
						
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
	
	
							38 lines
						
					
					
						
							1.4 KiB
						
					
					
				<?php
 | 
						|
 | 
						|
namespace App\Http\Controllers\Api\V1;
 | 
						|
 | 
						|
use App\Http\Controllers\Controller;
 | 
						|
use App\Models\Notification;
 | 
						|
use App\Models\UserNotification;
 | 
						|
use Illuminate\Http\Request;
 | 
						|
use App\CentralLogics\Helpers;
 | 
						|
 | 
						|
class NotificationController extends Controller
 | 
						|
{
 | 
						|
    public function get_notifications(Request $request){
 | 
						|
 | 
						|
        if (!$request->hasHeader('zoneId')) {
 | 
						|
            $errors = [];
 | 
						|
            array_push($errors, ['code' => 'zoneId', 'message' => 'Zone id is required!']);
 | 
						|
            return response()->json([
 | 
						|
                'errors' => $errors
 | 
						|
            ], 403);
 | 
						|
        }
 | 
						|
        $zone_id= json_decode($request->header('zoneId'), true);
 | 
						|
        try {
 | 
						|
            $notifications = Notification::active()->where('tergat', 'customer')->where(function($q)use($zone_id){
 | 
						|
                $q->whereNull('zone_id')->orWhereIn('zone_id', $zone_id);
 | 
						|
            })->where('created_at', '>=', \Carbon\Carbon::today()->subDays(15))->get();
 | 
						|
            $notifications->append('data');
 | 
						|
 | 
						|
            $user_notifications = UserNotification::where('user_id', $request->user()->id)->where('created_at', '>=', \Carbon\Carbon::today()->subDays(15))->get();
 | 
						|
            $notifications =  $notifications->merge($user_notifications);
 | 
						|
            return response()->json($notifications, 200);
 | 
						|
        } catch (\Exception $e) {
 | 
						|
            info(['Notification api issue_____',$e->getMessage()]);
 | 
						|
            return response()->json([], 200);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 |