Create relationship task_user

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-11-14 09:46:57 +01:00
parent f353e0c964
commit 71fc82a0e7
3 changed files with 40 additions and 1 deletions
+5
View File
@@ -22,4 +22,9 @@ class Task extends Model
public function event() {
return $this->belongsTo(Events::class);
}
public function users() {
return $this->belongsToMany(User::class);
}
}
+4
View File
@@ -50,4 +50,8 @@ class User extends Authenticatable
'password' => 'hashed',
];
}
public function tasks() {
return $this->belongsToMany(Task::class);
}
}
@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('task_user', function (Blueprint $table) {
$table->id();
$table->foreignId('task_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};