# laravel-9 **Repository Path**: accumulate-steadily/laravel-9 ## Basic Information - **Project Name**: laravel-9 - **Description**: php(laravel9)+mysql5.7 bbs论坛功能 - **Primary Language**: PHP - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: http://larabbs.3qma.com/ - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2022-11-03 - **Last Updated**: 2024-11-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: bbs ## README # 目录 - [数据填充,重新生成](php artisan migrate:refresh --seed) - 本地化(多国语言) - 本地搭建 mailhog - 代码生成器 - Debugbar 开发工具 - [N+1问题: 预加载](https://learnku.com/docs/laravel/9.x/eloquent-relationships/12252#eager-loading) - [作用域](https://learnku.com/docs/laravel/6.x/eloquent/5176) - [Simditor编译器](https://simditor.tower.im/) - [XSS](http://htmlpurifier.org/) - [HTML Purifier for Laravel](https://github.com/mewebstudio/Purifier) - [百度翻译](http://api.fanyi.baidu.com/api/trans/product/apidoc) - [拼音-安正超](https://github.com/overtrue/pinyin) - [Predis](composer require "predis/predis:~1.1") - [horizon 队列管理工具](https://learnku.com/docs/laravel/9.x/horizon/12268) - [Supervisor安装](https://learnku.com/docs/laravel/9.x/horizon/12268) - [Supervisor 使用总结](https://learnku.com/articles/36939) - [sql日志写入文件](\App\Listeners\DBQueryListener) - [ Laravel Administrator 通过配置文件创建后台](https://learnku.com/laravel/t/2407/use-laravel-administrator-to-quickly-generate-data-model-administrator-tutorial) - [活跃用户的算法规则](https://learnku.com/laravel/t/2902/algorithm-for-active-users) - [计划任务的配置](#计划任务) ## 安装和使用 ```shell git clone 到本地 composer install cp .env.example .env 配置好数据库 和 redis,邮箱 php artisan migrate --seed 登录访问 账号/密码: fan@example.com / password (或数据库表users中的其它账号,默认密码都是 password) ``` ## 功能开发记录 ### 本地化(多国语言) ```shell ## 安装 composer require "overtrue/laravel-lang:~6.0" php artisan lang:publish zh_CN ``` ```php # 配置文件 'locale' => 'zh_CN', ``` ```php ## 使用 __("Forget Password?") ``` ### 本地搭建 mailhog ```shell script # 很简单 https://github.com/mailhog/MailHog ``` ### 代码生成器 https://github.com/summerblue/generator ```shell php artisan make:scaffold Topic --schema="title:string:index,body:text,user_id:bigInteger:unsigned:index,category_id:integer:unsigned:index,reply_count:integer:unsigned:default(0),view_count:integer:unsigned:default(0),last_reply_user_id:integer:unsigned:default(0),order:integer:unsigned:default(0),excerpt:text:nullable,slug:string:nullable" ``` - 创建话题的数据库迁移文件 —— 2018_12_23_104258_create_topics_table.php; - 创建话题数据工厂文件 —— TopicFactory.php; - 创建话题数据填充文件 —— TopicsTableSeeder.php; - 创建模型基类文件 —— Model.php, 并创建话题数据模型; - 创建话题控制器 —— TopicsController.php; - 创建表单请求的基类文件 —— Request.php,并创建话题表单请求验证类; - 创建话题模型事件监控器 TopicObserver 并在 AppServiceProvider 中注册; - 创建授权策略基类文件 —— Policy.php,同时创建话题授权类,并在 AuthServiceProvider 中注册; - 在 web.php 中更新路由,新增话题相关的资源路由; - 新建符合资源控制器要求的三个话题视图文件,并存放于 resources/views/topics 目录中; - 执行了数据库迁移命令 artisan migrate; - 因此次操作新建了多个文件,最终执行 composer dump-autoload 来生成 classmap。 ### Debugbar 开发工具 ```shell composer require "barryvdh/laravel-debugbar:~3.6" --dev ``` ### artisan 命令 ```shell php artisan migrate:refresh --seed # 回滚数据库的所有迁移,--seed 同时运行 db:seed ``` ##计划任务配置 ```shell $ export EDITOR=vim && crontab -e * * * * * php /your/project/path/artisan schedule:run >> /dev/null 2>&1 ``` - 按大写的 G (或者按方向键)将光标移动到最底端; - 然后按键盘上的 『小写 o 键』进入 INSERT 模式; - 黏贴上面这一行; - 黏贴成功后按下键盘左上角的『ESC 键』进入 VI 的命令模式; - 键盘输入 :wq 并敲击回车键保存退出 系统的 Cron 已经设定好了,现在 Cron 软件将会每分钟调用一次 Laravel 命令调度器,当 schedule:run 命令执行时, Laravel 会评估你的计划任务并运行预定任务。 接下来将我们注册调度任务即可: app/Console/Kernel.php ```php protected function schedule(Schedule $schedule) { // $schedule->command('inspire') // ->hourly(); // 一小时执行一次『活跃用户』数据生成的命令 $schedule->command('larabbs:calculate-active-user')->hourly(); } # php artisan cache:clear 清空缓存,查看对比效果 ```