0

I create a project based on the book Getting Started with Laravel 4.

So, I create two files in app/models/ - Cat.php and Breed.php with this content:

Cat.php

<?php

class Cat extends Eloquent {
    protected $fillable = array('name','date_of_birth','breed_id');

    public function breed() {
        return $this->belongsTo('Breed');
    }
}

and Breed.php

<?php

class Breed extends Eloquent {
    public $timestamps = false;

    public function cats()
    {
        return $this->hasMany('Cat');
    }
}

and after, I use command php artisan migration:make create_cats_and_breeds_table

Ok, and should arise file in app/database/migrations. It is.

But, its contents it's not same as in the book...

In book:

<?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');
    }

}

My code:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddCatsAndBreedsTable extends Migration {

    public function up()
    {
        //
    }

    public function down()
    {
        //
    }

}

What's happen?

User002
  • 13
  • 4
  • The code you have is only the skeleton. Enter the column definition in up method and run migration command. – usrNotFound Aug 13 '15 at 09:14
  • @CannotFindSymbol , I know that this skeleton but that was generated by the command. A should be generated as it is in the book. – User002 Aug 13 '15 at 09:24
  • `php artisan generate:migration create_posts_table --fields="title:string, body:text"` this might help you dude. Good luck – usrNotFound Aug 13 '15 at 09:28

2 Answers2

0

migration:make command does not know anything about your models. It just creates a stub that you need to fill with column definitions for your tables.

jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
  • hmmm, but according to the book, you should be generated full code – User002 Aug 13 '15 at 09:12
  • What book? Either you have misread it or the book lies. Migrate command has never generated column definitions for you. It would be impossible - in Eloquent you do not define a list of fields in your models so it has no idea what attributes your model has or what their types might be. Notice that you also do not pass model names to the command, so that's another reason why it would be impossible. – jedrzej.kurylo Aug 13 '15 at 09:34
0

https://github.com/laracasts/Laravel-4-Generators

Provides some additional artisan commands which you can used to specific your fields in order to generate the migration files.

php artisan generate:migration create_posts_table --fields="title:string, body:text"
nathanmac
  • 455
  • 1
  • 6
  • 14