File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Http \Controllers ;
4+
5+ use Illuminate \Http \Request ;
6+ use App \Models \User ;
7+ use App \Models \Apartment ;
8+ use App \Models \Message ;
9+ class NotificationController extends Controller
10+ {
11+ public function index ()
12+ {
13+ $ user = auth ()->user ();
14+ $ apartments = Apartment::where ('user_id ' , $ user ->id )->with ('messages ' )->get ();
15+ $ newMessages = [];
16+
17+ foreach ($ apartments as $ apartment ) {
18+ foreach ($ apartment ->messages as $ message ) {
19+ if ($ message ['created_at ' ] > now ()->subMinutes (5 )) {
20+ $ newMessages [] = $ message ;
21+ }
22+ }
23+ }
24+
25+ return response ()->json ($ newMessages );
26+ }
27+ }
Original file line number Diff line number Diff line change 55use App \Http \Controllers \Api \ApartmentApi ;
66use App \Http \Controllers \ImageUploadController ;
77use App \Http \Controllers \Api \ReceiverController as EmailReceiverController ;
8+ use App \Http \Controllers \NotificationController ;
89/*
910|--------------------------------------------------------------------------
1011| API Routes
2021 return $ request ->user ();
2122});
2223
24+ // Notification con Auth
25+ Route::middleware ('auth:sanctum ' )->get ('/notifications ' , [NotificationController::class, 'index ' ]);
26+ // debugging
27+ // Route::get('/notifications/{id}', [NotificationController::class, 'index']);
28+
2329Route::get ('geocode ' , function (Request $ request ) {
2430 $ apiKey = 'SooRbYbji9V5qUxAh3i2ijnD8m9ZWVZ7 ' ;
2531 // utilizzo bounding box per la zona di ricerca lombarda
You can’t perform that action at this time.
0 commit comments