add alersts api
This commit is contained in:
35
app/Http/Controllers/AlertController.php
Normal file
35
app/Http/Controllers/AlertController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AlertController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get alerts for user
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$alerstQuery = auth()->user()->alerts()->whereNull('seen_at');
|
||||
|
||||
$alerts = $alerstQuery->get();
|
||||
|
||||
$alerstQuery->update([
|
||||
'seen_at' => now()
|
||||
]);
|
||||
|
||||
return response()->json($this->format($alerts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format
|
||||
*/
|
||||
public function format($alerts)
|
||||
{
|
||||
return $alerts->map(fn ($alert) => [
|
||||
'name' => $alert->name,
|
||||
'value' => $alert->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user