Tag: Laravel

  • Nested JSON Validation in Laravel / Lumen

    Nested JSON Validation in Laravel / Lumen

    我们可能会提交这样一个请求,一个 嵌套的 JSON 对象,那么如何对 JSON 对象的那边元素进行验证呢? ### Save Post Comments POST {{API_BASE_URL}}/module/v1/posts/2/comments Content-Type: application/json Accept: application/json Authorization: Bearer {{TOKEN}} { "data": [ { "media_ids": [1,2,3], "title": "Title A", "status": "A", "comment": "Objectively seize progressive ROI before unique bandwidth." }, { "media_ids": [4,5,6], "title": "Title B", "status": "B", "comment": "Objectively mesh sticky value for global data.…

  • Laravel/Lumen Customizing Monolog For Channels

    Laravel/Lumen Customizing Monolog For Channels

    官方文档 https://laravel.com/docs/6.x/logging#creating-monolog-handler-channels 首先 新建一个 文件: 如官方文档所示,可以在 __invoke 方法里定制你的 logger,例如你想要 json 格式的日志的话: 更多设置: 输出的日志样本如下: { “message”: “Undefind method: \”asdasdad\””, “context”: {}, “level”: 400, “level_name”: “ERROR”, “channel”: “local”, “datetime”: “2020-05-11T17:05:07.231673+08:00”, “extra”: { “user_id”: “guest”, “roles”: “NULL”, “process_id”: 13, “url”: “/data/v1/download?action=asdasdad&token=1”, “ip”: “172.25.0.1”, “http_method”: “GET”, “server”: “_”, “referrer”: null, “memory_usage”: “2 MB”, “file”: “/var/www/html/app/Http/Controllers/DownloadController.php”, “line”: 69, “class”: “App\\Http\\Controllers\\DownloadController”,…

  • Allow CORS in Laravel or Lumen

    Allow CORS in Laravel or Lumen

    首先创建一个中间件,lumen 需要手动创建 更新 app/Http/Middleware/Cors.php Laravel: 注册中间件到 app/Http/kernel.php Lumen: 修改 bootstrap/app.php 最后,您想要启用CORS的任何路由,只需在路由注册中添加此中间件。 Laravel, add test routers in routes/api.php Lumen: