代码改变世界

laravel基础

2018-01-16 17:31  小丸子的路飞  阅读(288)  评论(0)    收藏  举报

## laravel

### laravel 基础知识

1. 服务端后台默认运行laravel-echo
nohup laravel-echo-server start &
2. 后台默认开启队列
nohup php artisan queue:listen &


### laravel学习比较优秀的文章

1. [关联关系详细说明](http://laravelacademy.org/post/6996.html#toc_5)
2. [多对多关系 实现文章和tags](http://www.cnblogs.com/huangshoushi/p/5877756.html)
3. [多对多关系](http://www.bubuko.com/infodetail-1134393.html)
2. [Laravel技巧之 Pivot](https://laravel-china.org/articles/3798/laravel-skills-pivot)
2. [laravel官网路由规则](https://laravel.com/docs/5.4/validation#rule-unique)
3. [快速构建 RESTful API 以及现代化 Web 应用的 Laravel 原型项目 —— Someline](http://laravelacademy.org/post/6408.html)
4. [在 Laravel 5 中使用 Repository 模式实现业务逻辑和数据访问的分离](http://laravelacademy.org/post/3063.html)
5. [larvavel学院君](http://laravelacademy.org/post/author/nonfu)
6. [Golang实现的接口在线文档管理系统 ](https://github.com/lifei6671/mindoc)
7. [https://www.oschina.net/p/smartwiki]()[SmartWiki帮助手册](https://wiki.iminho.me/docs/show/1)
8. [laravel学习网站](https://phpartisan.cn)
9. [Laravel Search](http://laravelacademy.org/post/3781.html)
10. [Laravel5.2使用RabbitMQ](http://blog.csdn.net/sinat_21125451/article/details/53422648)
11. [laravel 基础教程 —— 测试](http://www.jianshu.com/p/d8b3ac2c4623)
12. [写 Laravel 测试](https://segmentfault.com/blog/lx1036)
13. [Laravel 5.1 LTS 速查表](https://cs.laravel-china.org/#)
14. [修改 Request headers 不完全攻略](https://laravel-china.org/topics/3430/modify-request-headers-incomplete-raiders)
15. [在 Laravel 5 中通过 Simple QrCode 扩展包生成二维码详解](http://laravelacademy.org/post/2605.html)
16. [laravel的transformer](https://zhuanlan.zhihu.com/p/25554084)
17. [迷思](https://zhuanlan.zhihu.com/prattle?topic=API)


### laravel问题解决

1. 开启事务,使用`sharedLock()`造成死锁.

解决方案: 每一次接口返回时,都先`DB::commit()`.

2. laravel错误处理 `failed to open stream: Permission denied`
1. php artisan cache:clear
2. chmod -R 777 storage(文件名)
3. composer dump-autoload

### laravel常用命令

1. 启动队列完整命令
程序命令: `php artisan queue:work --daemon --quiet --queue=default --delay=3 --sleep=3 --tries=3`

参数解释:

--daemon: 可以节省CPU,在supervisor中一般要加这个option

--quiet: 不输出任何内容

--delay=3: 一个任务失败后,延迟 `多次时间`后再重试,单位是秒.这个值设定建议不要太短,因为一个任务失败(比如网络原因),重试时间太淡可能会出现连续失败的问题

--sleep=3: 入redis中拿任务的时候,发现没有任务,休息`多长时间`,单位是秒.这个值的设定要看你的任务是否紧急,如果是那种非常紧急的任务,不能等待太长时间.

--tries=3: 定义`失败任务最多重试次数`.这个值的设定根据任务的重要程度来确定,一般3次比较适合.

2. 清除项目缓存

php artisan cache:clear
3. 清除配置缓存

php artisan config:cache