FEATURE: add structure for categories

This commit is contained in:
Michal Kváček
2016-08-11 00:26:52 +02:00
parent 778c87ffa3
commit 03f0d71dbb
4 changed files with 97 additions and 0 deletions
+1
View File
@@ -154,6 +154,7 @@ return [
App\Providers\ModuleManager::class,
Pingpong\Modules\ModulesServiceProvider::class,
Pingpong\Menus\MenusServiceProvider::class,
Franzose\ClosureTable\ClosureTableServiceProvider::class,
\Watson\Sitemap\SitemapServiceProvider::class,
/*
* Application Service Providers...
@@ -0,0 +1,61 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCategoriesTable extends Migration
{
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->softDeletes();
$table->integer('parent_id')
->unsigned()
->nullable();
$table->integer('position', false, true);
$table->integer('real_depth', false, true);
$table->integer('user_id')
->comment('Author of this category');
$table->integer('module_id')
->comment('ID of module, where this category is used');
$table->string('name')
->comment('Human readable name of category');
$table->string('url')
->index()
->comment('URL slug of category');
$table->text('description');
$table->unique(['url', 'module_id']);
});
Schema::table('categories', function (Blueprint $table) {
$table->foreign('parent_id')
->references('id')
->on('categories')
->onDelete('set null');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('module_id')
->references('id')
->on('modules')
->onDelete('cascade')
->onUpdate('cascade');
});
}
public function down()
{
Schema::table('categories', function (Blueprint $table) {
Schema::dropIfExists('categories');
});
}
}
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCategoryClosuresTable extends Migration
{
public function up()
{
Schema::create('category_closure', function (Blueprint $table) {
$table->increments('closure_id');
$table->integer('ancestor', false, true);
$table->integer('descendant', false, true);
$table->integer('depth', false, true);
$table->foreign('ancestor')
->references('id')
->on('categories')
->onDelete('cascade');
$table->foreign('descendant')
->references('id')
->on('categories')
->onDelete('cascade');
});
}
public function down()
{
Schema::table('category_closure', function (Blueprint $table) {
Schema::dropIfExists('category_closure');
});
}
}