resolve conflits

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-11-20 09:01:13 +01:00
22 changed files with 277 additions and 152 deletions
@@ -0,0 +1,38 @@
<?php
namespace App\Http\Controllers;
use App\Models\Notification;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class NotificationsController extends Controller
{
public function create(Request $request, int $id): JsonResponse {
$notification = Notification::create([
"content" => $request["content"]
]);
$notification->users()->attach($id);
return response()->json(['message' => 'Notification created successfully']);
}
public function getNotifications(Request $request, int $id): JsonResponse {
try {
$user = User::findOrFail($id);
return response()->json([
'data' => $user->notifications
]);
} catch(\Exception $e) {
Log::info($e->getMessage());
return response()->json(['message' => "Server error"], 500);
}
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
protected $fillable = [
'content',
];
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(User::class, 'user_notification', 'notification_id', 'user_id');
}
}
+5
View File
@@ -54,4 +54,9 @@ class User extends Authenticatable
public function tasks() {
return $this->belongsToMany(Task::class);
}
public function notifications(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Notification::class, 'user_notification', 'user_id', 'notification_id');
}
}