🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
| 扩展包 | 说明 | | --- | --- | | [laravel-lang/lang(opens new window)](https://publisher.laravel-lang.com/installation/) | 语言包 | | [endroid/qr-code(opens new window)](https://github.com/endroid/qr-code) | 二维码生成 | | [erusev/parsedown(opens new window)](https://github.com/erusev/parsedown) | Markdown 解析器 | | [hisorange/browser-detect(opens new window)](https://github.com/hisorange/browser-detect) | 设备检测 | | [houdunwang/arr(opens new window)](https://github.com/houdunwang/arr) | 数据增强 | | [mewebstudio/captcha(opens new window)](https://github.com/mewebstudio/captcha) | 图形验证码 | | [mews/purifier(opens new window)](https://github.com/mewebstudio/purifier) | html 安全处理 | | [nwidart/laravel-modules(opens new window)](https://nwidart.com/laravel-modules/v6/introduction) | 项目模块化处理 | | [socialiteproviders/wechat-web(opens new window)](https://socialiteproviders.com/WeChatWeb/) | 微信客户端 H5 登录 | | [socialiteproviders/weixin-web](https://doc.houdunren.com/%E6%8F%92%E4%BB%B6%E6%89%A9%E5%B1%95/Laravel/socialiteproviders/weixin-web) | 微信 PC 扫码登录 | | [spatie/image(opens new window)](https://spatie.be/docs/image/v1/usage/basic-usage) | 图片压缩处理(推荐) | | [Intervention/image(opens new window)](https://github.com/Intervention/image) | 图像处理库 | | [spatie/laravel-activitylog(opens new window)](https://spatie.be/docs/laravel-activitylog/v4/introduction) | 网站动态 | | [spatie/laravel-permission(opens new window)](https://spatie.be/docs/laravel-permission/v3/installation-laravel#) | 基于角色的权限控制 | | [yansongda/pay(opens new window)](https://github.com/yansongda/pay) | 多平台支付处理 | | [barryvdh/laravel-debugbar(opens new window)](https://github.com/barryvdh/laravel-debugbar) | 调试面板 | | [barryvdh/laravel-ide-helper(opens new window)](https://github.com/barryvdh/laravel-ide-helper) | 生成自动提示文件 | | [laravel-api-response-helpers(opens new window)](https://github.com/f9webltd/laravel-api-response-helpers) | api资源响应帮助函数 | | [overtrue/easy-sms](https://github.com/overtrue/easy-sms) | 发送短信 | | [mpdf/mpdf](https://github.com/mpdf/mpdf) | pdf生成 | | [overtrue/laravel-pinyin](https://github.com/overtrue/laravel-pinyin) | Laravel-Pinyin | | [opcodesio/log-viewer](https://github.com/opcodesio/log-viewer) | opcodesio/log-viewer | | [textalk/websocket](https://github.com/Textalk/websocket-php) | textalk/websocket | | [intervention/image](https://image.intervention.io/v2/introduction/installation) | Intervention Image php 图片处理 | ## 多语言 默认表单提示是英文的,我们可以安装[语言包(opens new window)](https://publisher.laravel-lang.com/)构建多语言环境。 ~~~ composer require --dev laravel-lang/common laravel-lang/publisher laravel-lang/lang laravel-lang/attributes laravel-lang/http-statuses ~~~ 接下来发布服务提供者 ~~~ php artisan vendor:publish --provider="LaravelLang\Publisher\ServiceProvider" ~~~ 然后在命令行执行以下指令,添加中文语言包到**resource/lang**目录 ~~~ php artisan lang:add zh_CN php artisan lang:add ug ~~~ 修改`config/app.php`配置文件,设置语言包(即语言包的目录名) ~~~ 'locale' => 'zh_CN', ~~~ ## 验证码 使用[mewebstudio/captcha](https://doc.houdunren.com/%E6%8F%92%E4%BB%B6%E6%89%A9%E5%B1%95/Laravel/mewebstudio/captcha)可以方便的生成网站图形验证码。 ![Preview](https://doc.houdunren.com/assets/img/68747470733a2f2f696d6167652e6962622e636f2f6b5a784d4c6d2f696d6167652e706e67-3556057.d2f863f7.png) 请参考官网文档进行安装,下面介绍如果生成支持前后台分离的验证码。 修改**.env**配置文件,开启验证码 ~~~ CAPTCHA_DISABLE=false ~~~ 在前台框架 vue 或 react 中向以下地址发送请求,获取验证码数据 ~~~ http://localhost/captcha/api/math ~~~ 在 postman 中测试接口,可以得到以下数据 ~~~ { "sensitive": false, "key": "$2y$10$819PNm1n6567hQRLoKpadOS6n.8u0F5YmnR6Nrw57KvmRL4z8gPDe", "img": "data:image/png;base64..." } ~~~ 前台需要把 key 与用户输入的验证码数据提交到后台,然后使用以下表单验证规则进行验证 ~~~ $rules = ['captcha' => 'required|captcha_api:'. request('key') . ',math']; ~~~ 有时前端需要设置代理,下面是**vite**中的代理设置 ~~~ server: { host: true, proxy: { '/api': { target: env.VITE_API_URL, changeOrigin: true, }, //验证码接口 '/captcha/api/math': { target: env.VITE_API_URL, changeOrigin: true, }, }, }, ~~~ ## 设备判断 判断移动、平板设备等场景还是很常见的。使用[browser-detect(opens new window)](https://github.com/hisorange/browser-detect)可以很容易的进行设备判断。 **安装扩展** ~~~ composer require hisorange/browser-detect ~~~ **常用功能** 下面介绍常用的功能,更多功能的使用请查看[官方文档(opens new window)](https://github.com/hisorange/browser-detect#)。 **判断浏览器** ~~~ use Browser; // 判断设备类型 Browser::isMobile(); Browser::isTablet(); Browser::isDesktop(); // 浏览器检测 if (Browser::isFirefox() || Browser::isOpera()) { $response .= '<script src="firefox-fix.js"></script>'; } // 操作系统检测 if (Browser::isAndroid()) { $response .= '<a>Install our Android App!</a>'; } elseif (Browser::isMac() && Browser::isMobile()) { $response .= '<a>Install our iOS App!</a>'; } ~~~ **blade 模板** ~~~ @mobile <p>这是移动模板!</p> @include('your-mobile-template') @endmobile @tablet <p>这是平板模板!</p> <link rel="stylesheet" href="tablet.css" title="Reduce the page size, load what the user need"> @endtablet @desktop <p>这是桌面模板!</p> @enddesktop ~~~ ## 图片处理 使用[spatie/image(opens new window)](https://github.com/spatie/image)扩展包可以进行图片压缩、裁切等处理。 **安装扩展包** ~~~ composer require spatie/image ~~~ **等比例裁切图片** 下面是等比例以原图片中心裁切图片,并将裁切后的图片保存为 public/images/test.jpeg ~~~ Image::load('images/hd.jpeg') ->crop(Manipulations::CROP_CENTER, 500, 100) ->save(public_path('images/test.jpeg')); ~~~ # pdf生成 先安装 ~~~ composer require mpdf/mpdf ~~~ 添加font ![](https://img.kancloud.cn/e6/b7/e6b7aff6d4e6206fb10c59e9af0f1dd5_435x464.png) 然后配置字体 ![](https://img.kancloud.cn/ea/83/ea83df89a6ba20b631c5abcf787802a7_1447x811.png) ~~~ "alkatip" => [ 'R' => "alkatipbasmatom.ttf", 'B' => "alkatipbasmatom.ttf", 'I' => "alkatipbasmatom.ttf", 'BI' => "alkatipbasmatom.ttf", 'useOTL' => 0xFF, 'useKashida' => 75, ], "ukiji" => [ 'R' => "UKIJTor.ttf", 'B' => "UKIJTor.ttf", 'I' => "UKIJTor.ttf", 'BI' => "UKIJTor.ttf", 'useOTL' => 0xFF, 'useKashida' => 75, ], ~~~ > 我使用的UKIJTor,alkatip 测试没通过 使用方法 ~~~ $mpdf = new Mpdf([ 'mode' => 'utf-8', 'margin_top' => 30, 'margin_left' => 30, 'margin_right' => 30, 'default_font' =>'ukiji' //'default_font' =>'alkatip' ]); $mpdf->SetHeader($header_title); $mpdf->defaultheaderline = 1;//页眉线宽度 $mpdf->defaultfooterline = 1;//页脚线宽度 /*pdf头部*/ $mpdf->WriteHTML($html); $out_file = “www/wwwroot/admin/public/test.pdf” $mpdf->Output($out_file,'f'); ~~~ # Intervention Image php 图片处理 ~~~ <?php namespace App\Services; use Illuminate\Support\Facades\Storage; use Intervention\Image\ImageManagerStatic as Image; class ImageService{ public function __construct(){ require_once base_path('package/intervention_image/autoload.php'); } //压缩并且添加水印 public function remoteImageResizeAndWatermark($img_file, $width = 0, $height = 0, $limiter_width = 700){ $source_img = Storage::disk('ftp_root')->url($img_file); //打开资源图片 $image = Image::make($source_img); //打开水印图片 $watermark = Image::make(public_path('icon/watermark.png')); //宽度大于 700 ,压缩图片 if ($image->width() > $limiter_width){ $image = $image->resize($width, $height); //添加水印 $watermark = $watermark->resize($width, $height); }else{ //添加水印 $watermark = $watermark->resize($image->width(), $image->height()); } $image->insert($watermark); $image->save_uqur($img_file); return $img_file; } } ~~~ or ~~~ // include composer autoload require 'vendor/autoload.php'; // import the Intervention Image Manager Class use Intervention\Image\ImageManagerStatic as Image; // configure with favored image driver (gd by default) Image::configure(['driver' => 'imagick']); // and you are ready to go ... $image = Image::make('public/foo.jpg')->resize(300, 200); ~~~