jampot5000/eloquent-scientist

允许使用 Scientist 库与 Laravel PHP 框架配合。

v1.0.0 2016-09-20 02:07 UTC

This package is not auto-updated.

Last update: 2024-09-18 18:51:12 UTC


README

允许使用 Scientist 库Laravel PHP 框架 一起使用,并添加迁移/模型以使用 eloquent 存储结果信息。

安装

使用 Composer 需要安装 Eloquent Scientist 的最新版本。

composer require jampot5000/eloquent-scientist

接下来,将服务提供者添加到你的 Laravel 项目的 config/app.php 文件的 providers 部分。

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => [

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
        
        Jampot5000\EloquentScientist\ServiceProvider::class,

    ],
    
];

config/app.phpaliases 部分注册 Facade。

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => [

        'URL'       => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View'      => Illuminate\Support\Facades\View::class,
        
        'Scientist' => Jampot5000\EloquentScientist\Facade::class,

    ],

];

运行迁移

php artisan migrate

你已经准备好使用了!

可选

你可以发布配置文件

    php artisan vendor:publish

这将允许你配置使用的模型并添加额外的报告器

使用方法

你可以通过 Scientist Facade 访问 Eloquent Scientist 实验室。

<?php

$value = Scientist::experiment('foo')
    ->control($controlCallback)
    ->trial('First trial.', $trialCallback)
    ->run();

或者,将实验室注入到一个解析的类或控制器操作中。

<?php

use Scientist\Laboratory;

class FooController extends Controller
{
    public function index(Laboratory $laboratory)
    {
        return $laboratory->experiment('foo')
            ->control(function() { ... })
            ->trial('First trial.', function() { ... })
            ->run();
    }
}

请参阅 Scientist 文档以获取更多信息!

致谢

Dayle Rees - 为将 Scientist 库移植到 PHP 以及这个想法的原始 Laravel 包。

待办事项

  • 测试
  • 视图