35 lines
661 B
PHP
35 lines
661 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
class AlertController extends Controller
|
|
{
|
|
/**
|
|
* Get alerts for user
|
|
*/
|
|
public function index()
|
|
{
|
|
return auth()->id();
|
|
$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,
|
|
]);
|
|
}
|
|
}
|