Created
April 27, 2015 11:39
-
-
Save Stichoza/444b16aecc26b73b9ede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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