当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::getConnection方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getConnection方法的具体用法?PHP Model::getConnection怎么用?PHP Model::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import

 /**
  * Import an Eloquent
  *
  * @param Model $model
  * @param array $relations
  * @param int $batchSize
  * @param callable $callback
  * @internal param $type
  */
 public function import(Model $model, $relations = [], $batchSize = 750, callable $callback = null)
 {
     $batch = 0;
     $asQueryLoggind = $model->getConnection()->logging();
     $model->getConnection()->disableQueryLog();
     while (true) {
         // Increase the batch number
         $batch += 1;
         // Load records from the database
         $records = $model->newInstance()->with($relations)->skip($batchSize * ($batch - 1))->take($batchSize)->get();
         // Break out of the loop if we are out of records
         if (count($records) == 0) {
             break;
         }
         // Call the callback function to provide feedback on the import process
         if ($callback) {
             $callback($batch);
         }
         // Transform each record before sending it to Elasticsearch
         $data = [];
         foreach ($records as $record) {
             $data[] = ['index' => ['_id' => $record->getEsId()]];
             $data[] = $record->transform(!empty($relations));
         }
         // Bulk import the data to Elasticsearch
         $this->bulk($data);
     }
     if ($asQueryLoggind) {
         $model->getConnection()->enableQueryLog();
     }
 }
开发者ID:menthol,项目名称:Flexible,代码行数:40,代码来源:Index.php

示例2: addMockConnection

 /**
  * Set mock connection.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  */
 protected function addMockConnection(Model $model)
 {
     $resolver = m::mock('\\Illuminate\\Database\\ConnectionResolverInterface');
     $model->setConnectionResolver($resolver);
     $resolver->shouldReceive('connection')->andReturn(m::mock('\\Illuminate\\Database\\Connection'));
     $model->getConnection()->shouldReceive('getQueryGrammar')->andReturn(m::mock('\\Illuminate\\Database\\Query\\Grammars\\Grammar'));
     $model->getConnection()->shouldReceive('getPostProcessor')->andReturn(m::mock('\\Illuminate\\Database\\Query\\Processors\\Processor'));
 }
开发者ID:DavidIWilson,项目名称:site1,代码行数:13,代码来源:EloquentConnectionTrait.php

示例3: apply

 /**
  * {@inheritDoc}
  * @see \Illuminate\Database\Eloquent\ScopeInterface::apply()
  */
 public function apply(Builder $builder, Model $model)
 {
     /**
      * @var $model Model
      */
     $name = $model::getBootUseToTraitProperyName();
     $value = $model::${$name};
     $value = $model->getConnection()->getPdo()->quote($value);
     $builder->where($model->getQualifiedUseToFieldName(), new Expression($value));
     $this->addWithTrashed($builder);
 }
开发者ID:windqyoung,项目名称:utils,代码行数:15,代码来源:UseToScope.php

示例4: schemaFields

 /**
  * Create fields for type.
  *
  * @return void
  */
 protected function schemaFields()
 {
     $table = $this->model->getTable();
     $schema = $this->model->getConnection()->getSchemaBuilder();
     $columns = collect($schema->getColumnListing($table));
     $columns->each(function ($column) use($table, $schema) {
         if (!$this->skipField($column)) {
             $this->generateField($column, $schema->getColumnType($table, $column));
         }
     });
 }
开发者ID:nuwave,项目名称:laravel-graphql-relay,代码行数:16,代码来源:EloquentType.php

示例5: transaction

 /**
  * @param Closure $closure
  * @return mixed
  * @throws Exception
  */
 protected function transaction(Closure $closure)
 {
     $connection = $this->model->getConnection();
     $connection->beginTransaction();
     try {
         $result = $closure();
         $connection->commit();
         return $result;
     } catch (Exception $e) {
         $connection->rollBack();
         throw $e;
     }
 }
开发者ID:cloudcreativity,项目名称:laravel-json-api,代码行数:18,代码来源:EloquentController.php

示例6: performTransaction

 public function performTransaction($amount, $sender_id, $recipient_id)
 {
     $connection = Eloquent::getConnection();
     try {
         $connection->getPdo()->beginTransaction();
         $sender = Balance::where('character_id', $sender_id)->first();
         $recipient = Balance::where('character_id', $recipient_id)->first();
         $sender->update(['amount' => $sender->amount - $amount]);
         $recipient->update(['amount' => $recipient->amount + $amount]);
         $connection->getPdo()->commit();
     } catch (\Exception $e) {
         $connection->getPdo()->rollback();
         return false;
     }
     return true;
 }
开发者ID:MichaelLeah,项目名称:GalacticBank,代码行数:16,代码来源:Transaction.php

示例7: database

 protected function database(Model $model)
 {
     return $model->getConnection()->table($model->getTable());
 }
开发者ID:jaffle-be,项目名称:framework,代码行数:4,代码来源:AdminTestCase.php

示例8: getPropertiesFromTable

 /**
  * Load the properties from the database table.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 protected function getPropertiesFromTable($model)
 {
     $table = $model->getTable();
     $schema = $model->getConnection()->getDoctrineSchemaManager($table);
     $schema->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
     $columns = $schema->listTableColumns($table);
     if ($columns) {
         foreach ($columns as $column) {
             $name = $column->getName();
             $type = $column->getType()->getName();
             switch ($type) {
                 case 'string':
                 case 'text':
                 case 'date':
                 case 'time':
                 case 'guid':
                     $type = 'string';
                     break;
                 case 'integer':
                 case 'bigint':
                 case 'smallint':
                     $type = 'integer';
                     break;
                 case 'decimal':
                 case 'float':
                     $type = 'float';
                     break;
                 case 'boolean':
                     $type = 'boolean';
                     break;
                 case 'datetimetz':
                     //String or DateTime, depending on $dates
                 //String or DateTime, depending on $dates
                 case 'datetime':
                     $type = '\\Carbon\\Carbon';
                     break;
                 default:
                     $type = 'mixed';
                     break;
             }
             $this->setProperty($name, $type, true, true);
         }
     }
 }
开发者ID:ngogiangthanh,项目名称:code-nien-luan-ktpm-k36,代码行数:49,代码来源:ModelsCommand.php

示例9: getTableColumns

 private function getTableColumns(Model $model)
 {
     return $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable());
 }
开发者ID:roshangara,项目名称:datatables-handler,代码行数:4,代码来源:DatatablesHandler.php

示例10: __construct

 /**
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 public function __construct(Model $model)
 {
     $this->model = $model;
     $this->db = $model->getConnection();
 }
开发者ID:legalweb,项目名称:php-statistics-helper,代码行数:8,代码来源:AbstractEloquentStatisticsProvider.php

示例11: delete

 /**
  * Delete entity values.
  *
  * @throws \InvalidArgumentException
  */
 public function delete()
 {
     if (!in_array(SoftDeletes::class, class_uses_recursive(get_class($this->entity)), true) || $this->entity->forceDeleting) {
         $instance = new Value();
         $connection = $this->entity->getConnection();
         $connection->table($instance->getTable())->where('entity_id', $this->entity->getKey())->whereIn('property_id', $this->properties->pluck('id'))->delete();
     }
 }
开发者ID:dkulyk,项目名称:eloquent-extra,代码行数:13,代码来源:Factory.php

示例12: getConnection

 /**
  * {@inheritdoc}
  */
 protected function getConnection()
 {
     return $this->model->getConnection();
 }
开发者ID:viniciusferreira,项目名称:laravel-repository,代码行数:7,代码来源:EloquentRepository.php

示例13: getNullable

 /**
  * Check if column is nullable.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  string  $column
  * @return bool
  */
 public function getNullable($model, $column)
 {
     $schema = $model->getConnection()->getDoctrineSchemaManager($model->getTable());
     $columns = $schema->listTableColumns($model->getTable());
     return isset($columns[$column]) ? !$columns[$column]->getNotnull() : false;
 }
开发者ID:ThisVessel,项目名称:Caravel,代码行数:13,代码来源:DbalHelpers.php

示例14: getPropertiesFromTable

 /**
  * Load the properties from the database table.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 protected function getPropertiesFromTable($model)
 {
     $table = $model->getConnection()->getTablePrefix() . $model->getTable();
     $schema = $model->getConnection()->getDoctrineSchemaManager($table);
     $databasePlatform = $schema->getDatabasePlatform();
     $databasePlatform->registerDoctrineTypeMapping('enum', 'string');
     $platformName = $databasePlatform->getName();
     $customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", array());
     foreach ($customTypes as $yourTypeName => $doctrineTypeName) {
         $databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
     }
     $database = null;
     if (strpos($table, '.')) {
         list($database, $table) = explode('.', $table);
     }
     $columns = $schema->listTableColumns($table, $database);
     if ($columns) {
         foreach ($columns as $column) {
             $name = $column->getName();
             if (in_array($name, $model->getDates())) {
                 $type = 'datetime';
             } else {
                 $type = $column->getType()->getName();
             }
             if (!($model->incrementing && $model->getKeyName() === $name) && $name !== $model::CREATED_AT && $name !== $model::UPDATED_AT) {
                 if (!method_exists($model, 'getDeletedAtColumn') || method_exists($model, 'getDeletedAtColumn') && $name !== $model->getDeletedAtColumn()) {
                     $this->setProperty($name, $type);
                 }
             }
         }
     }
 }
开发者ID:mpociot,项目名称:laravel-test-factory-helper,代码行数:37,代码来源:GenerateCommand.php

示例15: getPropertiesFromTable

 /**
  * Load the properties from the database table.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 protected function getPropertiesFromTable($model)
 {
     $table = $model->getConnection()->getTablePrefix() . $model->getTable();
     $schema = $model->getConnection()->getDoctrineSchemaManager($table);
     $schema->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
     $columns = $schema->listTableColumns($table);
     if ($columns) {
         foreach ($columns as $column) {
             $name = $column->getName();
             if (in_array($name, $model->getDates())) {
                 $type = '\\Carbon\\Carbon';
             } else {
                 $type = $column->getType()->getName();
                 switch ($type) {
                     case 'string':
                     case 'text':
                     case 'date':
                     case 'time':
                     case 'guid':
                     case 'datetimetz':
                     case 'datetime':
                         $type = 'string';
                         break;
                     case 'integer':
                     case 'bigint':
                     case 'smallint':
                         $type = 'integer';
                         break;
                     case 'decimal':
                     case 'float':
                         $type = 'float';
                         break;
                     case 'boolean':
                         $type = 'boolean';
                         break;
                     default:
                         $type = 'mixed';
                         break;
                 }
             }
             $this->setProperty($name, $type, true, true);
             $this->setMethod(Str::camel("where_" . $name), '\\Illuminate\\Database\\Query\\Builder|\\' . get_class($model), array('$value'));
         }
     }
 }
开发者ID:erpio,项目名称:Reportula,代码行数:50,代码来源:ModelsCommand.php


注:本文中的Illuminate\Database\Eloquent\Model::getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。