laravel new article
chmod -R 777 storage
127.0.0.1 article.ioa.tw
~/www/article/public
sudo apachectl restart
article.ioa.tw
修改 /.env
資料庫連線方式,分別填入連線方式、資料庫名稱、使用者、密碼
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
php artisan make:migration create_articles_table
編輯 /database/migrations/
剛剛新增的 migration file
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id')->unsigned()->comment ('主 Key');
$table->string('title')->comment ('標題');
$table->text('content')->comment ('內容');
$table->timestamps();
});
}
public function down()
{
Schema::drop('articles');
}
php artisan migrate
退回指令
php artisan migrate:rollback
php artisan make:controller ArticlesController
php artisan make:model Article
/app/Http/routes.php
Route::resource('articles', 'ArticlesController');
article.ioa.tw/articles
link_to_route()
的方式,例如 {!! link_to_route('articles.index', '列表') !!}
,第一個變數可參考下表的 route 名稱<a href="{{ route("articles.index") }}">列表</a>
,函式 route()
的第一個變數可參考下表的 route 名稱Method | url | 行為 | route 名稱 |
---|---|---|---|
GET | /articles | index | articles.index |
GET | /articles/create | create | articles.create |
POST | /articles | create post | articles.store |
GET | /articles/{article id} | show | articles.show |
GET | /articles/{article id}/edit | edit | articles.edit |
PUT | /articles/{article id} | edit post | articles.update |
DELETE | /articles/{article id} | destroy | articles.destroy |
composer.json
require 加入 laravelcollective/html
"require": {
"laravelcollective/html": "5.1.*"
}
更新 composer update
這步驟會有點久....
修改 cache 權限 chmod -R 777 bootstrap/cache
修改 config/app.php
,providers 加入 Collective\Html\HtmlServiceProvider::class,
,aliases 加入 'Form' => Collective\Html\FormFacade::class,
以及 'Form' => Collective\Html\FormFacade::class,
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class,
// ...
],
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
// ...
],
程式碼範例:OA's practice laravel5 CRUD
相關參考: