laravelcollective 5.2
編輯 composer.json
composer update
{
// ... ...
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "5.2.*" //新增
},
介紹文章 - Forms & HTML 组件 - laravelcollective/html開啟 Windows cmd 視窗, 進入網頁資料夾根目錄 執行 composer update
D:\www\mylaravel>composer update
> php artisan clear-compiled
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing laravelcollective/html (v5.2.3)
Loading from cache
Writing lock file
Generating autoload files
> php artisan optimize
Generating optimized class loader
D:\www\mylaravel>
編輯 config/app.php
'providers' => [
// ...
Collective\Html\HtmlServiceProvider::class, //新增
],
// ...
'aliases' => [
// ...
'Form' => Collective\Html\FormFacade::class, //新增
'Html' => Collective\Html\HtmlFacade::class, //新增
],
這樣就可以開始使用了。 補充: composer.json 那一行,如果是放在最後面,不可以有逗號。config/app.php 則允許最後一行有逗號。
設定資料庫
修改資料庫連線資訊
//根目錄 .env
DB_HOST=localhost
DB_DATABASE=mylaravel
DB_USERNAME=root
DB_PASSWORD=mypassword
// config\database.php 這個檔暫時先不改
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
在 users 資料表新增 username 欄位
編輯 migration database/migrations/xxx_create_users_table.php
目前系統內建的檔名是 2014_10_12_000000_create_users_table.php。
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('password', 60);
$table->string('name');
$table->string('nickname');
$table->rememberToken();
$table->timestamps();
});
}
不知道為什麼沒有 username。name 應該是像 Ron Lee 這樣,帳號 username 是 ronlee。所以自己新增這一欄。讓 Laravel 新增資料表
D:\www\mylaravel>php artisan migrate:install Migration table created successfully. 原本空白的資料庫這時候會產生第一張資料表 migrations D:\www\mylaravel>php artisan migrate Migrated: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_100000_create_password_resets_table 資料庫會再多兩張表:users, password_resets。因為這時候在 database/migrations 裡有兩個 migration 檔案。
認證
系統內建 Auth 控制器,但沒有 view。新增 Auth 的 view。
(這一段請參考 Laravel 官網的"認證")
D:\www\mylaravel>php artisan make:auth Created View: D:\www\mylarave\resources/views/auth/login.blade.php Created View: D:\www\mylarave\resources/views/auth/register.blade.php Created View: D:\www\mylarave\resources/views/auth/passwords/email.blade.php Created View: D:\www\mylarave\resources/views/auth/passwords/reset.blade.php Created View: D:\www\mylarave\resources/views/auth/emails/password.blade.php Created View: D:\www\mylarave\resources/views/layouts/app.blade.php Created View: D:\www\mylarave\resources/views/home.blade.php Created View: D:\www\mylarave\resources/views/welcome.blade.php Installed HomeController. Updated Routes File. Authentication scaffolding generated successfully!
完成以上步驟,登入機制就完成了。
登入頁
註冊帳號
寫入資料庫了
登入成功
laravel遇到class not found的解决办法




沒有留言:
張貼留言