Skip to content

Commit 89d35e1

Browse files
committed
feat: add migration for news categories table
1 parent d00a632 commit 89d35e1

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*/
14+
public function up(): void
15+
{
16+
Schema::create('news_categories', function (Blueprint $table) {
17+
$table->increments('id');
18+
19+
$table->string('title')->default('');
20+
$table->integer('parent_id')->default(-1);
21+
$table->integer('weight')->default(0);
22+
$table->softDeletes();
23+
24+
$table->index(['weight'], 'idx_weight');
25+
$table->timestamps();
26+
});
27+
28+
Schema::create('pivot_news_categories', function (Blueprint $table) {
29+
$table->increments('id');
30+
$table->unsignedInteger('news_id');
31+
$table->unsignedInteger('category_id');
32+
33+
$table->index('news_id');
34+
$table->index('category_id');
35+
$table->unique(['news_id', 'category_id']);
36+
});
37+
}
38+
39+
/**
40+
* Reverse the migrations.
41+
*/
42+
public function down(): void
43+
{
44+
Schema::dropIfExists('news_categories');
45+
Schema::dropIfExists('pivot_news_categories');
46+
}
47+
};

src/FilamentNewsServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ protected function getMigrations(): array
146146
{
147147
return [
148148
'create_news_table',
149+
'create_news_categories_table',
149150
];
150151
}
151152
}

0 commit comments

Comments
 (0)