Skip to content

Instantly share code, notes, and snippets.

@Stichoza
Created April 27, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stichoza/444b16aecc26b73b9ede to your computer and use it in GitHub Desktop.
Save Stichoza/444b16aecc26b73b9ede to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoriesTableWithI18n extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function(Blueprint $table)
{
$table->increments('id');
//
$table->unsignedInteger('parent_id')->nullable();
$table->foreign('parent_id')
->references('id')
->on('categories')
->onUpdate('cascade')
->onDelete('set null');
$table->string('title');
//
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('categories');
}
}
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model {
protected $table = 'categories';
protected $fillable = [
'parent_id',
'title',
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment