composer切換國(guó)內(nèi)鏡像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
開啟多線程下載
composer global require hirak/prestissimo
安裝laravel5.8
composer create-project --prefer-dist laravel/laravel laravel 5.8.*
創(chuàng)建laravel自帶用戶模塊(項(xiàng)目根目錄執(zhí)行下面代碼):
php artisan make:auth
配置多語言
- 在resources下面創(chuàng)建一個(gè)zh.json的文件
{
"Login":"登錄",
"E-Mail Address" : "郵箱",
"Remember Me":"記住我",
"Forgot Your Password":"忘記密碼",
"Password" : "密碼",
"E-Mail Address": "郵箱地址"
}
- 打開config下面的app.php
找到'locale' => 'en',
修改為'locale' => 'zn',
模板文件改為調(diào)用語言文件的
image.png
數(shù)據(jù)遷移(migrate)
php artisan migrate
如果報(bào)錯(cuò)(mysql5.6版本索引長(zhǎng)度不一樣所致)
image.png
找到
\app\Providers
下面AppServiceProvider.php
的boot方法,添加下面代碼
Schema::defaultStringLength(191);
把生成的表刪除再重新運(yùn)行命令即可
使用migrate創(chuàng)建表
php artisan make:migration CreateXXXXTable
然后在up方法創(chuàng)建字段
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->integer('post_id');
$table->text('content')->comment('評(píng)論內(nèi)容');
$table->timestamps();
});
}
接下來運(yùn)行命令
php artisan migrate
查看數(shù)據(jù)庫,表完成
創(chuàng)建模型(model)
model是創(chuàng)建在app根目錄下的洒琢,不過可以自定義路徑
php artisan make:model Models/Posts
打開posts.php文件
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Posts extends Model
{
//定義表名
provided $table = 'posts';
//白名單(這些可以修改)
//protected $fillable = ['name'];
//protected $guarded = ['price'];
//需要注意的是衰抑,fillable 與 guarded 只限制了 create 方法,而不會(huì)限制 save。
provided $fillable = [
'user_id','title','content',
];
}
創(chuàng)建控制器
php artisan make:controller IndexController