Switch language
zh
Switch theme
Light
  • laravel-路由参数与控制器进行隐性绑定

    // 路由文件 Route('topics/{topic}', 'TopicsController@show'); // 控制器 public function show(Topics $topic) { // todo } 其中路由中的 {topic} 是与 控制器中的 $topic 进行绑定的, 如果前面写成 id, 后面则用 $id, 也能正确进行模型绑定 // 路由文件 Route('topics/{id}', 'TopicsController@show'); // 控制器 public function show(Topics $id) { // todo } 参考自 learnku
  • laravel-request-中-使用路由参数

    在 Controller 中使用请求参数直接使用 $request->input(’name’) 或 $request->name; 在 Controller 中使用路由参数直接使用 参数注入 或 $request->name; 在 Request 中, 使用请求参数使用 $this->input(’name’) 或 $this->name 在 Request 中, 使用请求参数使用 $this->name, (不能使用参数注入) 在使用动态属性时,Laravel 首先会在请求载体中查找参数的值。如果该值不存在,Lavarel 将在路由参数中搜索。
  • access_token-和-refresh_token

    设置 access_token 为 1 天有效期, refresh_token 为 7 天有效期, 如果 access_token 未过期, 则直接通过登录判断 (不更新 access_token 或 refresh_token ) 当 access_token 过期, 则检测 refresh_token , refresh_token 未过期时, 更新并返回 access_token 和 refresh_token 当 access_token 过期, refresh_token 也过期, 则返回未登录 ps: 由于 refresh_token 的有效期大于 access_token 的有效期 (而二者是同时更新的), 所以不存在 access_token 未过期, 而 refresh_token 过期的情况
  • lnmp-环境中-使用-system-函数被报安全因素无法启用

    原因: 要在 php 中使用 mysqldump 进行数据库备份 在本地 wamp 环境中使用没有问题 在线上 lnmp 环境下报错 system 函数无法使用 解决办法: 查看线上 php.ini 文件是否开启 safe_mode (安全模式); 2.1.1 如果开启了 安全模式, 则查看 disable_function 是否禁用了 system 函数 2.1.2 如果 disable_function 是禁用了 system 函数, 那么取消禁用, 并在 safe_mode_exec_dir 中添加一个包含要执行命令的目录 2.2.1 如果未开户安全模式, 直接查看 disable_function 是否禁用了 system 函数, 取消掉即可
  • 让-tp5-api-返回-json-格式的异常

    见: https://blog.csdn.net/qq_38287952/article/details/80247000
  • 如何让-Laravel-API-永远返回-JSON-格式响应?

    见: https://www.jianshu.com/p/c0b7365a21e5 当你在编写完全为 API 服务的 Laravel 应用时,你希望所有响应都是 JSON 格式的,而不是例如说授权错误会重定向到 /home 或 /login,最终重定向会变成 InvalidArgumentException: Route [login] is not defined. 的视图。 下面这个简单的方案,可以让你的 Laravel 应用优先响应为 JSON 格式。 第一步、编写 BaseRequest 首先我们需要构建一个 BaseRequest 来重写 Illuminate\Http\Request ,修改为默认优先使用 JSON 响应: app/Http/Requests/BaseRequest.php
  • php-json_decode-函数

    json_decode 把 json 字符串转成 object 或 array $str = '{"id":1, "name":"hello"}'; $obj = json_decode($str); // 转成对象 $arr = json_decode($str, true);// 转成数组 // 要求 // json 字符串中的键值必须用 双引号("") 包裹起来, 单引号或者不用引号都不能正确解析, 结果会是 null
  • fastadmin----跨域问题

    原文见: https://forum.fastadmin.net/thread/7485 在入口文件 index.php 中添加如下代码 header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET, POST"); header("Access-Control-Allow-Headers: Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With");
  • fastadmin----nginx-配置----解决除首页外的404问题

    原文见: https://forum.fastadmin.net/thread/8320 在 nginx 配置文件中加入如下代码 server { ``` listen 80; server_name www.abc.com abc.com; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/abc/public; location / { index index.html index.htm index.php; #autoindex on; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 #error_page 404/404.html; #SSL-END #ERROR-PAGE-START 错误页配置,可以注释、删除或修改 error_page 404 /404.html; error_page 502 /502.html; #ERROR-PAGE-END #PHP-INFO-START PHP引用配置,可以注释或修改 include enable-php-72.conf; #PHP-INFO-END #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效 #include /www/server/panel/vhost/rewrite/www.xfguoye.com.conf; #REWRITE-END #禁止访问的文件或目录 location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } #一键申请SSL证书验证目录相关设置 location ~ \.
  • tp5-数据集(对象)转成数组(再转json)输出

    原文见: https://www.jianshu.com/p/a69164fd1f50?utm_campaign 先在数据库配置文件中 // 数据集返回类型 'resultset_type' => 'collection', 在使用时, 使用 toArray() 方法 // 查询数据库 $news = NewsModel::order('createtime desc')->limit($num)->page($page)->select()->toArray(); /* array (size=2) 0 => array (size=8) 'id' => int 2 'title' => string '2' (length=1) 'title_image' => string '2' (length=1) 'label_name' => string '2' (length=1) 'content' => string '<p>2</p>' (length=8) 'link_url' => string '2' (length=1) 'createtime' => int 1549338746 'updatetime' => int 1549338746 1 => array (size=8) 'id' => int 1 'title' => string 'dd' (length=2) 'title_image' => string '' (length=0) 'label_name' => string '' (length=0) 'content' => string 'dd' (length=2) 'link_url' => string '' (length=0) 'createtime' => int 11 'updatetime' => int 11 */
🍀