记录学习 laravel 项目的个人理解… 持续 updating…
//查看所有 artisan 命令
php artisan list
// 查看不同 - 命令
php artisan make:controller TestController -help
.env 文件中
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com // 如果用 gmail 就改为 smtp.gmail.com
MAIL_PORT=465 // 下面的 ENCRYPTION 如果是 ssl,端口号为 465
[email protected] // 修改为自己的邮箱地址
MAIL_PASSWOR=****** // 填写邮箱的授权码
MAIL_ENCRYPTION=ssl // 加密类型,可为不填或 ssl 或 tls,如果上面的 MAILER 选择 smtp,ENCRYPTION 填 ssl
[email protected] // 修改为自己的邮箱地址
MAIL_FROM_NAME=test // 发送邮件时显示的名字
谷歌邮箱授权码获取方式见 Gmail 官网文档
composer.json 中包含使用 composer 安装的各个依赖 (比如 laravel ui, laravel passport…)
// 安装依赖 (读取 composer.json ,检查是否含有 composer-lock.json,检查更新信息,并安装依赖)
composer install
// 显示项目所有的依赖
composer show --tree
npm install
webpack.mix.js 中为 webpack 相关配置。用于前后端都有的 laravel 项目。
例如…使用 npm run dev 编译并打包前端资源,下面的代码会把 resources/js/app.js 编译为浏览器可识别的 javascript 代码,放入 public/js 中
mix.js('resources/js/app.js', 'public/js')
经常碰到各种奇奇怪怪的错误,明明觉得写的没错但是还是报错,清除缓存大法
// 清除 route 缓存和 config 缓存
php artisan optimize
// Flush the application cache
php artisan cache:clear
// Remove the configuration cache file
php artisan config:clear
// Clear all cached events and listeners
php artisan event:clear
// Flush expired password reset tokens
php artisan auth:clear-resets
// Remove the route cache file
php artisan route:clear
// Clear all compiled view files
php artisan view clear
比如,刚写好一个路由,但是浏览器访问显示 404,使用 php artisan route:clear 再进去就可以了。
Laravel 8 中提供了两种新的方式定义路由
// 方法一
use App\Http\Controllers\TestController;
Route::get('/test', [TestController::class, 'index']);
// 方法二
Route::get('/test', 'App\Http\Controllers\TestController::class@index');
低于 Laravel 8 的版本中
Route::get('/test', 'TestController@index');