laravel_command

laravel5基本命令

1.创建某个文件夹下的controller

php artisan make:controller Admin/ArticlesController

2.创建model

php artisan make:model Article

3.为已有表添加字段,创建migration

php artisan make:migration add_article_id_to_comments_table

修改migration

public function up()
{
    Schema::table('comments', function($table)
    {
        $table->integer('article_id');

    });
}

执行迁移命令

php artisan migrate

4.数据填充,在/databases/seeds/新建PageTableSeeder.php文件

<?php

use Illuminate\Database\Seeder;
use App\Page;

class PageTableSeeder extends Seeder {

  public function run()
  {
    DB::table('pages')->delete();

    for ($i=0; $i < 10; $i++) {
      Page::create([
        'title'   => 'Title '.$i,
        'slug'    => 'first-page',
        'body'    => 'Body '.$i,
        'user_id' => 1,
      ]);
    }
  }

}

修改DatabaseSeeder.php中

// $this->call('UserTableSeeder');

$this->call('PageTableSeeder');

然后运行命令

composer dump-autoload
php artisan db:seed

5.安装依赖包

php composer.phar install