美文网首页
Phalapi use laravel's eloque

Phalapi use laravel's eloque

作者: fizzday | 来源:发表于2018-08-30 13:33 被阅读113次

    Booter

    a mini booter of some services .

    Installation

    Use composer to manage your dependencies and download:

    composer require fizzday/booter
    

    Example

    • 1.Eloquent

      • config & boot
      <?php
      use Fizzday\Booter\Booter;
      $config = array(
                    'default' => 'mysql',
      
                    'connections' => array(
                        'mysql' => array(
                            'driver' => 'mysql',
                            'host' => '192.168.200.248',
                            'port' => '3306',
                            'database' => 'wcc_service_yxpt',
                            'username' => 'gcore',
                            'password' => 'gcore',
                            'charset' => 'utf8',
                            'collation' => 'utf8_unicode_ci',
                            'prefix' => '',
                        ),
                    );
      Booter::bootEloquent($config);
      
      • usage
      <?php
      
      use Illuminate\Database\Eloquent\Model as Model;
      use Illuminate\Database\Capsule\Manager as DB;
      
      class UserModel extends Model {
          protected $table = "prefix_users";
      }
      
      // eloquent 调用
      UserModel::first();
      
      // query builder 调用
      DB::table("users")->First();
      

    phalapi 中调用

    ~/phalapi/config/di.php中添加代码:

    <?php
    ......
        use Fizzday\Booter\Booter;
        $config = array(
                      'default' => 'mysql',
    
                      'connections' => array(
                          'mysql' => array(
                              'driver' => 'mysql',
                              'host' => '192.168.200.248',
                              'port' => '3306',
                              'database' => 'wcc_service_yxpt',
                              'username' => 'gcore',
                              'password' => 'gcore',
                              'charset' => 'utf8',
                              'collation' => 'utf8_unicode_ci',
                              'prefix' => '',
                          ),
                      );
        $di->db = Booter::bootEloquent($config);
    ......
    

    当然, 这里可以将配置文件抽取放到单独文件中

    相关文章

      网友评论

          本文标题:Phalapi use laravel's eloque

          本文链接:https://www.haomeiwen.com/subject/suirwftx.html