Getting Started with Laravel 4という本に基づいてプロジェクトを作成します。
そこで、app/models/ に 2 つのファイル (Cat.php と Breed.php) を次の内容で作成します。
Cat.php
<?php
class Cat extends Eloquent {
protected $fillable = array('name','date_of_birth','breed_id');
public function breed() {
return $this->belongsTo('Breed');
}
}
および Breed.php
<?php
class Breed extends Eloquent {
public $timestamps = false;
public function cats()
{
return $this->hasMany('Cat');
}
}
その後、コマンドを使用しますphp artisan migration:make create_cats_and_breeds_table
OK、app/database/migrationsにファイルが作成されるはずです。です。
しかし、その内容は本と同じではありません...
本で:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddCatsAndBreedsTable extends Migration {
public function up()
{
Schema::create('cats', function($table)
{
$table->increments('id');
$table->string('name');
$table->date('date_of_birth');
$table->integer('breed_id')->nullable();
$table->timestamps();
})
Schema::create('breeds', function($table)
{
$table->increments('id');
$table->string('name');
})
}
public function down()
{
Schema::drop('cats');
Schema::drop('breeds');
}
}
私のコード:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddCatsAndBreedsTable extends Migration {
public function up()
{
//
}
public function down()
{
//
}
}
どうしたの?