1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class CreateLessonsTable. |
9
|
|
|
* Migration for Lesson model. |
10
|
|
|
*/ |
11
|
|
|
class CreateLessonsTable extends Migration |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Run the migrations. |
16
|
|
|
* |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function up() |
20
|
|
|
{ |
21
|
|
|
Schema::create('lessons', function (Blueprint $table) { |
|
|
|
|
22
|
|
|
$table->increments('id'); |
23
|
|
|
$table->integer('location_id')->unsigned()->nullable(); // One to many |
24
|
|
|
$table->integer('day_id')->unsigned()->nullable(); // One to many |
25
|
|
|
$table->integer('timeslot_id')->unsigned()->nullable(); // One to many |
26
|
|
|
$table->integer('classroom_id')->unsigned()->nullable(); // One to many On Classrom Model hasMany, on Lesson model belongsTo |
27
|
|
|
$table->string('state')->nullable(); |
28
|
|
|
$table->timestamps(); |
29
|
|
|
$table->foreign('location_id')->references('id')->on('locations'); |
30
|
|
|
$table->foreign('day_id')->references('id')->on('days'); |
31
|
|
|
$table->foreign('timeslot_id')->references('id')->on('timeslots'); |
32
|
|
|
$table->foreign('classroom_id')->references('id')->on('classrooms'); |
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
Schema::create('lesson_user', function (Blueprint $table) { |
|
|
|
|
36
|
|
|
$table->integer('lesson_id')->unsigned(); |
37
|
|
|
$table->integer('user_id')->unsigned(); |
38
|
|
|
$table->timestamps(); |
39
|
|
|
$table->unique(['lesson_id', 'user_id']); |
40
|
|
|
$table->foreign('lesson_id')->references('id')->on('lessons')->onDelete('cascade'); |
41
|
|
|
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); |
42
|
|
|
}); |
43
|
|
|
Schema::create('lesson_submodule', function (Blueprint $table) { |
|
|
|
|
44
|
|
|
$table->integer('lesson_id')->unsigned(); |
45
|
|
|
$table->integer('submodule_id')->unsigned(); |
46
|
|
|
$table->timestamps(); |
47
|
|
|
$table->unique(['lesson_id', 'submodule_id']); |
48
|
|
|
}); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Reverse the migrations. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function down() |
57
|
|
|
{ |
58
|
|
|
Schema::dropIfExists('lesson_user'); |
59
|
|
|
Schema::dropIfExists('lesson_submodule'); |
60
|
|
|
Schema::dropIfExists('lessons'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.