Просмотр исходного кода

presence - aggiunto campo motivation_course_id

ferrari 1 месяц назад
Родитель
Сommit
fffd6cd1b2

+ 6 - 0
app/Models/Presence.php

@@ -15,6 +15,7 @@ class Presence extends Model
         'member_course_id',
         'user_id',
         'motivation_id',
+        'motivation_course_id',
         'court_id',
         'instructor_id',
         'notes',
@@ -35,6 +36,11 @@ class Presence extends Model
         return $this->belongsTo(\App\Models\Motivation::class);
     }
 
+    public function motivationCourse()
+    {
+        return $this->belongsTo(\App\Models\Course::class, 'motivation_course_id');
+    }
+
     public function user()
     {
         return $this->belongsTo(\App\Models\User::class, 'user_id');

+ 35 - 0
database/migrations/2025_12_15_100649_add_motivation_course_id_to_presences_table.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('presences', function (Blueprint $table) {
+            $table->unsignedBigInteger('motivation_course_id')->nullable()->after('motivation_id');
+
+            $table->foreign('motivation_course_id', 'presences_motivation_course_id_foreign')->references('id')->on('courses')->onUpdate('cascade')->onDelete('cascade');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('presences', function (Blueprint $table) {
+            $table->dropForeign('presences_motivation_course_id_foreign');
+            $table->dropColumn('motivation_course_id');
+        });
+    }
+};