一、下载 laravel 5.5
composer create-project laravel/laravel=5.5.* laravel5.5_blade
新建数据库 laravel5.5_blade
修改 .evn 配置文件
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel5.5_blade
DB_USERNAME=laravel5.5_blade
DB_PASSWORD=laravel5.5_blade
修改中国时区,在 config/app.php 中修改
'timezone' => 'PRC',
切换目录
cd laravel5.5_blade
二、创建数据
执行数据迁移
php artisan migrate
如果报错
Specified key was too long; max key length is 1000 bytes
问题解决:在 AppServiceProvider 中调用 Schema::defaultStringLength 方法来实现配置:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
进入 tinker
php artisan tinker
创建用户数据
factory('App\User', 5)->create();
三、自定义视图标签
修改 app/Providers/AppServiceProvider.php
public function boot()
{
\Blade::if('isLogin', function (){
return auth()->check();
});
}
修改 resources/views/welcome.blade.php
@isLogin
已登录
@else
未登录
@endisLogin
启动 serve
php artisan serve
修改 routes/web.php
Route::get('/', function () {
auth()->loginUsingId(1);
return view('welcome');
});