小编Syn*_*kSA的帖子

扩展Laravel核心日志记录

因为我在理解事情时遇到了问题,所以我回来时会遇到更多的Laravel问题.

我再次尝试创建一个包来进行自己的日志记录.在做了一些额外的阅读并完成核心代码并尝试其他方法之后,我得出的结论是,我需要做的就是扩展laravel日志记录的核心功能,以便它记录到一个不同的路径自定义格式化程序

我已经创建了我的包.这是我的服务提供者类:

use Illuminate\Log\LogServiceProvider;

class VmlogServiceProvider extends LogServiceProvider {


    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        App::bind('log', function()
        {
            return new Vm\Vmlog\Vmlog;
        });     
        parent::boot();

    }

}

?>
Run Code Online (Sandbox Code Playgroud)

这是VmLog类

<?php namespace Vm\Vmlog;

use App;
use Illuminate\Support\ServiceProvider;
use Log;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\RotatingFileHandler;

class Vmlog extends \Illuminate\Log\Writer {


    protected $path;
    protected $formatter;
    protected $stream;
    protected $rotatingStream;

    public function __construct() {

        $output = APP_HOST."|%datetime%|%level%|%level_name%|".__METHOD__."|%message%|%context%".PHP_EOL;
        $this->path = VM_LOGPATH.APP_VLCODE."/".APP_VLCODE."_".APP_INSTANCE.".log";
        $this->formatter = new LineFormatter($output, $dateFormat); …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-4

3
推荐指数
1
解决办法
6644
查看次数

Laravel 并运行一批结果

我对 Laravelchunkeach分解结果集的功能感到头疼。

我有一张表,其中有一列processed值为0. 如果我运行以下代码,它将遍历所有 13002 条记录。

Record::where(['processed' => 0])->each(function ($record) { 
    Listing::saveRecord($record);
}, 500);
Run Code Online (Sandbox Code Playgroud)

此代码将运行所有 13002 条记录。但是,如果我添加一些代码将记录标记为已处理,事情就会变得非常糟糕。

Record::where(['processed' => 0])->each(function ($record) { 
    $listing_id = Listing::saveRecord($record);

    $record->listing_id = $listing_id;
    $record->processed = 1;
    $record->save();
}, 500);
Run Code Online (Sandbox Code Playgroud)

当此代码运行时,仅处理 6002 条记录。

根据我对事情的理解,在chunk( eachrun through chunk) 的每次迭代中,它正在执行一个新语句。

我是从使用 Yii2 过来的,我对这个举动很满意,除了这个打嗝,它让我把头发拉出来。Yii2 有类似的函数(eachbatch),但它们似乎使用结果集和指针,因此即使您在处理结果时更新表,它也不会影响您的结果集。

在 Laravel 中实际上有更好的方法来做到这一点吗?

php laravel laravel-5.2

3
推荐指数
1
解决办法
4927
查看次数

Laravel 4动态路由 - Overkill?

我们正在建立一个我们可以解决的Laravel 4基础项目.我想创建一个默认的路由规则,允许开发人员轻松敲打新页面,而不必担心向控制器添加路由,但要使其可以为任何更复杂的路由/控制器添加其他路由.

我创建了以下路由规则,但我想知道它是否过度杀伤.我自己对Laravel很新,所以我不确定我是否会以错误的方式解决这个问题,所以我想我会发布它并得到一些反馈.

Route::any('{controller}/{action?}/{args?}', function($controller, $action = 'index', $args = '')
{
    $cont = "Controller";
    $notFound = "NotFound";
    $params = explode("/", $args);
    $app = app();

    if (!class_exists($controller.$cont) || !function_exists($contName.$cont.".".$action)) {
        $controller = $notFound;
        $action = 'index';
    }

    $controller = $app->make($controller.$cont);
    return $controller->callAction($app, $app['router'], $action, $params);

 })
->where(array(
    'controller' => '[^/]+',
    'action' => '[^/]+',
    'args' => '[^?$]+'
));
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-4

2
推荐指数
1
解决办法
1238
查看次数

Swagger:不允许的附加属性:allOf

我试图通过使用allOf. 这是我的 swagger yaml 文件。

swagger: '2.0'
info:
  title: Test API
  version: '1'
basePath: /api/v1
schemes:
  - https
produces:
  - application/json

paths:
  /users:
    get:
      summary: Collection of users
      tags:
        - users
      responses:
        200:
          description: A list of Users
          schema:
            $ref: "#/definitions/Users"        
        500:
          $ref: "#/responses/BadRequest"

definitions:
  User:
    required:
      - username
    properties:
      firstName:
        type: string
      lastName:
        type: string
      username:
        type: string
  Users:
    type: array
    items:
      $ref: "#/definitions/User"

responses:
  NonSuccess:
    description: Generic response for all non-success responses
    schema:
      type: object
      required: …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-2.0 swagger-editor

2
推荐指数
1
解决办法
8670
查看次数