命令建立模型類

wensongyu發表於2015-08-28
php artisan make:model Article  
php artisan make:model Page  

 這樣,再在app目錄下就會有兩個檔案Article.php 和Page.php.

接下來進行 Article 和 Page 類對應的 articles 表和 pages表的資料庫遷移,進入 learnlaravel5/databases/migrations 資料夾。

*createarticles_table.php 中修改:

Schema::create(`articles`, function(Blueprint $table)  
{
    $table->increments(`id`);
    $table->string(`title`);
    $table->string(`slug`)->nullable();
    $table->text(`body`)->nullable();
    $table->string(`image`)->nullable();
    $table->integer(`user_id`);
    $table->timestamps();
});

*createpages_table.php 中修改:

Schema::create(`pages`, function(Blueprint $table)  
{
    $table->increments(`id`);
    $table->string(`title`);
    $table->string(`slug`)->nullable();
    $table->text(`body`)->nullable();
    $table->integer(`user_id`);
    $table->timestamps();
});

然後執行命令:

php artisan migrate  

成功以後, tables 表和 pages 表已經出現在了資料庫裡,去看看吧~


相關文章