随笔分类 - laravel
摘要:很久没写上传文件的功能,偶然在laravel中用jquery ajax发送FormData对象居然报错了,记录下解决方法。 路由 <?php Route::get('test/fileUpload', [TestController::class, 'fileUpload']); Route::po
阅读全文
摘要:这次是被坑了,在linux apache运行完好的代码放到IIS服务器上居然没有数据,检查发现居然出现了419错误,要求ajax post请求中应该包含csrf token字段。 然后就突然想起来了,上次相似的项目也发生过这样的问题,上次没记录,时日长久,这次居然一点儿也没想起来... 按照错误提示
阅读全文
摘要:记录下常用的laravel数据库操作 多个数据库连接 DB::connection('foo')->select(...); 底层PDO 实例 $pdo = DB::connection()->getPdo(); 执行原生SQL $users = DB::select('select * from
阅读全文
摘要:模板 //定义布局 <html> <head> <title>App Name - @yield('title')</title> </head> <body> @section('sidebar') This is the master sidebar. @show //@show 则在定义的同时
阅读全文
摘要:数组 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
阅读全文
摘要:laravel-snappy基于wkhtmltopdf工具,可以比较完美的将web页面转成pdf格式。 安装过程 顺便把laravel及laravel-snappy安装过程记录下 composer config -g repo.packagist composer https://mirrors.a
阅读全文
摘要:最近有一个需求,需要把页面上的echarts等js组件生成的图表放到pdf中。使用laravel框架,找到了laravel-snappy这个包,其底层是使用wkhtmltopdf来生成pdf。因为有把数据点都画到箱型图上的需求,找到了plotly.js这个组件,功能还是很强大的,可以轻松实现如下的效
阅读全文
摘要:Laravel 文档里面关于Sanctum 和Fortify的介绍 Laravel Sanctum 为 SPA(单页应用程序)、移动应用程序和基于令牌的、简单的 API 提供轻量级身份验证系统。Sanctum 允许应用程序的每个用户为他们的帐户生成多个 API 令牌。这些令牌可以被授予指定允许令牌执
阅读全文
摘要:最近要做发送邮件的功能,发送邮件的功能还是比较简单的,可以使用PHPMailer包 <?php $mail = new PHPMailer\PHPMailer(); try { $mail->addaddress('username@mail.com'); $mail->CharSet = 'UTF
阅读全文
摘要:多语言切换 config/app.php 中 locale 中默认为‘en’ 'locale' => 'zh_CN', 建立LanguageController namespace App\Http\Controllers; class LanguageController extends Cont
阅读全文
摘要:$query=DB::connection($conn)->table($table) ->select('*', DB::raw("CONCAT(date,' ',time) AS dttm")) ->where('P', $p) ->whereIn('status', $status) ->wh
阅读全文
摘要:宏指令允许添加自定义功能到 Laravel 的内部组件里去,App\Providers\AppServiceProvider boot()方法中注册。 Request #注册 Request::macro('introduce', function ($name) { return 'Hello '
阅读全文
摘要:安装代码包 composer require maatwebsite/excel 导出多个sheet //ExportMulSheets.php namespace App\Exports; use Maatwebsite\Excel\Concerns\Exportable; use Maatweb
阅读全文
摘要:use Illuminate\Support\Facades\Route; var_dump(url()->current()); //"http://127.0.0.1:8000/test/a1" var_dump(url()->previous()); //"http://127.0.0.1:8
阅读全文