- 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
This commit is contained in:
56
app/Http/Controllers/NotificationController.php
Normal file
56
app/Http/Controllers/NotificationController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user