1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Schema\Blueprint; |
4
|
|
|
use Illuminate\Database\Migrations\Migration; |
5
|
|
|
use Illuminate\Support\Facades\Schema; |
6
|
|
|
|
7
|
|
|
class CreateArticlesTable extends Migration |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Run the migrations. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function up() |
15
|
|
|
{ |
16
|
|
|
Schema::create('articles', function (Blueprint $table) { |
|
|
|
|
17
|
|
|
$table->increments('id'); |
18
|
|
|
$table->unsignedInteger('category_id')->index(); |
19
|
|
|
$table->string('title')->index(); |
20
|
|
|
$table->string('alias')->index(); |
21
|
|
|
$table->string('author_alias')->nullable()->index(); |
22
|
|
|
$table->string('blade_template')->nullable(); |
23
|
|
|
$table->text('body')->nullable(); |
24
|
|
|
$table->dateTime('publish_up')->nullable(); |
25
|
|
|
$table->dateTime('publish_down')->nullable(); |
26
|
|
|
$table->text('parameters')->nullable(); |
27
|
|
|
$table->unsignedInteger('order')->default(1); |
28
|
|
|
$table->integer('hits')->default(0); |
29
|
|
|
$table->boolean('published')->default(false)->index(); |
30
|
|
|
$table->boolean('authenticated')->default(false); |
31
|
|
|
$table->boolean('featured')->default(false); |
32
|
|
|
$table->boolean('is_page')->default(false); |
33
|
|
|
$table->string('authorization', 20)->default('can'); |
34
|
|
|
$table->unsignedInteger('created_by')->nullable()->index(); |
35
|
|
|
$table->unsignedInteger('updated_by')->nullable()->index(); |
36
|
|
|
$table->timestamps(); |
37
|
|
|
|
38
|
|
|
$table->foreign('category_id')->references('id')->on('categories'); |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
View Code Duplication |
Schema::create('article_permission', function(Blueprint $table) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$table->unsignedInteger('article_id')->index(); |
44
|
|
|
$table->unsignedInteger('permission_id')->index(); |
45
|
|
|
|
46
|
|
|
$table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade'); |
47
|
|
|
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade'); |
48
|
|
|
}); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Reverse the migrations. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function down() |
57
|
|
|
{ |
58
|
|
|
Schema::drop('article_permission'); |
59
|
|
|
Schema::drop('articles'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.