随笔分类 -  laravel

摘要:很久没写上传文件的功能,偶然在 laravel 中用 jquery ajax 发送 FormData 对象居然报错了,记录下解决方法。 路由 Route::get('test/fileUpload', [TestController::class, 'fileUpload']); Route::po 阅读全文
posted @ 2024-04-16 16:02 carol2014 阅读(88) 评论(0) 推荐(0)
摘要:这次是被坑了,在 linux apache 运行完好的代码放到 IIS 服务器上居然没有数据,检查发现居然出现了 419 错误,要求 ajax post 请求中应该包含 csrf token 字段。 检查发现:在 laravel 中间件 app/Http/Middleware/VerifyCsrfT 阅读全文
posted @ 2023-12-26 10:34 carol2014 阅读(217) 评论(0) 推荐(0)
摘要:记录下常用的 laravel 数据库操作 指定数据库连接 DB::connection('foo')->select(...); 底层 PDO 实例 $pdo = DB::connection()->getPdo(); 执行原生SQL $users = DB::select('select * fr 阅读全文
posted @ 2023-09-01 10:15 carol2014 阅读(46) 评论(0) 推荐(0)
摘要:数组 use Illuminate\Support\Arr; Arr::collapse([[1, 2, 3], [4, 5, 6], [7, 8, 9]]); // [1, 2, 3, 4, 5, 6, 7, 8, 9] Arr::flatten(['name' => 'Joe', 'langua 阅读全文
posted @ 2023-05-12 19:23 carol2014 阅读(401) 评论(0) 推荐(0)
摘要:laravel-snappy 基于 wkhtmltopdf 工具,可以比较完美的将 web 页面转成 pdf 格式。 安装过程 顺便把 laravel 及 laravel-snappy 安装过程记录下 composer config -g repo.packagist composer https: 阅读全文
posted @ 2023-05-11 16:54 carol2014 阅读(397) 评论(0) 推荐(0)
摘要:最近有一个需求,需要把页面上的 echarts 等 js 组件生成的图表放到 pdf 中。使用 laravel 框架,找到了 laravel-snappy 这个包,其底层是使用 wkhtmltopdf 来生成 pdf。因为有把数据点都画到箱型图上的需求,找到了plotly.js 这个组件,功能还是很 阅读全文
posted @ 2023-05-06 17:31 carol2014 阅读(144) 评论(0) 推荐(0)
摘要:Laravel 文档里面关于 Sanctum 和 Fortify 的介绍 Laravel Sanctum 为 SPA(单页应用程序)、移动应用程序和基于令牌的、简单的 API 提供轻量级身份验证系统。Sanctum 允许应用程序的每个用户为他们的帐户生成多个 API 令牌。这些令牌可以被授予指定允许 阅读全文
posted @ 2022-12-28 14:18 carol2014 阅读(1007) 评论(0) 推荐(0)
摘要:最近要做发送邮件的功能,发送邮件的功能还是比较简单的,可以使用 PHPMailer 包。 $mail = new PHPMailer\PHPMailer(); try { $mail->addaddress('username@mail.com'); $mail->CharSet = 'UTF-8' 阅读全文
posted @ 2022-12-16 15:01 carol2014 阅读(585) 评论(0) 推荐(0)
摘要:多语言切换 config/app.php 中 locale 中默认为 en 'locale' => 'zh_CN', 新建 LanguageController 用于切换语言 namespace App\Http\Controllers; class LanguageController exten 阅读全文
posted @ 2022-11-19 10:53 carol2014 阅读(364) 评论(0) 推荐(0)
摘要:laravel 查询构建器 $query=DB::connection($conn)->table($table) ->select('*', DB::raw("CONCAT(date,' ',time) AS dttm")) ->where('P', $p) ->whereIn('status', 阅读全文
posted @ 2022-11-19 10:47 carol2014 阅读(45) 评论(0) 推荐(0)
摘要:宏指令允许添加自定义功能到 Laravel 的内部组件里去,需要在 App\Providers\AppServiceProvider 的 boot() 方法中注册宏指令。 Request // 注册 Request::macro('introduce', function ($name) { ret 阅读全文
posted @ 2022-11-19 10:43 carol2014 阅读(379) 评论(0) 推荐(0)
摘要:安装代码包 composer require maatwebsite/excel 导出多个 sheet // ExportMulSheets.php namespace App\Exports; use Maatwebsite\Excel\Concerns\Exportable; use Maatw 阅读全文
posted @ 2022-11-19 10:28 carol2014 阅读(496) 评论(0) 推荐(0)
摘要:laravel获取当前路由 use Illuminate\Support\Facades\Route; var_dump(url()->current()); //"http://127.0.0.1:8000/test/a1" var_dump(url()->previous()); //"http 阅读全文
posted @ 2022-11-19 09:12 carol2014 阅读(524) 评论(0) 推荐(0)