laravel 学习踩坑小记
1.前端渲染bug
今天在学习laravel+vue时编译时
npm run watch
查看Chrome浏览器老是提示组件未注册
查看代码没问题
后来换一个浏览器发现不报错了
可能是浏览器缓存了旧的js数据
清楚浏览器数据果然不报错了
很多时候我们首先会想到是代码的问题 没想到bug会出在浏览器身上
2.用户关联bug
Class 'App\Models\Userfollowers' not found (View: D:\Doc\web\PHP\laravel\laravel\resources\views\user.blade.php)
检查代码发现在定义关联关系时错了一个标点符号
//User.php
public function following(){
$this->belongsToMany(User::class.'followers','user_id','follower_id');
}
因为对框架的不熟悉导致花费大量时间去测试代码而没能从bug信息中去寻找错误点。。
一个个小小的错误真是要人命
3 .数据库迁移错误
php artisan migrate
报错信息:1071 specified key was too long
解决方法:
//文件AppServiceProvider
use Illuminate\Support\Facades\Schema;
public function boot()
{
//
Schema::defaultStringLength(191);
}
4.curl 60 使用GitHub oauth认证时报错
cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
解决方案:
1.下载cacert
下载地址https://curl.haxx.se/ca/cacert.pem
2.配置php.ini 并重启
在php.ini中找到curl.cainfo改为文件的绝对路径如:curl.cainfo =E:\phpstudy\PHPTutorial\php\php-7.2.1-nts\cacert.pem
注意事项:
需要开启 php_curl、php_openssl 扩展;
5Laravel-Admin 创建Controller出错
1.出错原因
系统不一样执行命令不一样
2.解决方法
linux\mac: php artisan admin:make UsersController --model=App\\Mdoels\User
windows:php artisan admin:make UsersController --model=App\Models\User
5.启动队列报错
1.出错原因
用的windows系统 未安装redis扩展