Some checks failed
continuous-integration/drone/push Build is failing
- Complete GGZ Ecademy Laravel backend application - RESTful API for learning products, members, filters - Authentication and authorization system - Database migrations and seeders - Custom CRUD generator commands - Email notification system - Integration with frontend applications
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Notifications\CustomNotification;
|
|
use App\Http\Resources\UserLoggedResource;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth:sanctum');
|
|
}
|
|
|
|
public function markAsRead(Request $request)
|
|
{
|
|
$notification = auth()->user()->notifications()->find($request->id);
|
|
if ($notification) {
|
|
$notification->markAsRead();
|
|
return response()->json(new UserLoggedResource(auth()->user()));
|
|
}
|
|
}
|
|
|
|
public function markAsUnread(Request $request)
|
|
{
|
|
$notification = auth()->user()->notifications()->find($request->id);
|
|
if ($notification) {
|
|
$notification->read_at = null;
|
|
$notification->save();
|
|
return response()->json(new UserLoggedResource(auth()->user()));
|
|
}
|
|
}
|
|
|
|
public function delete(Request $request)
|
|
{
|
|
$notification = auth()->user()->notifications()->find($request->id);
|
|
if ($notification) {
|
|
$notification->delete();
|
|
return response()->json(new UserLoggedResource(auth()->user()));
|
|
}
|
|
}
|
|
|
|
public function test()
|
|
{
|
|
if (!auth()->user()) return;
|
|
|
|
$demo_notification = new CustomNotification(
|
|
'Subject',
|
|
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ab dolores libero at dolorem unde, consequuntur sed eveniet totam aperiam aspernatur.'
|
|
);
|
|
|
|
auth()->user()->notify($demo_notification);
|
|
broadcast(new \App\Events\UserInfoUpdated(auth()->user()));
|
|
}
|
|
}
|