コード例 #1
0
 /**
  * Find a model by its primary key.
  *
  * @param mixed $id
  * @param array $columns
  *
  * @return \Illuminate\Database\Eloquent\Model|static|null
  */
 public function find($id, $columns = array('*'))
 {
     Event::fire('before.find', array($this));
     $result = parent::find($id, $columns);
     Event::fire('after.find', array($this));
     return $result;
 }
コード例 #2
0
ファイル: Model.php プロジェクト: blechdom/inventory
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     return $query->where('name', 'LIKE', "%{$search}%")->orWhere('modelno', 'LIKE', "%{$search}%")->orWhere(function ($query) use($search) {
         $query->whereHas('depreciation', function ($query) use($search) {
             $query->where('name', 'LIKE', '%' . $search . '%');
         });
     })->orWhere(function ($query) use($search) {
         $query->whereHas('category', function ($query) use($search) {
             $query->where('name', 'LIKE', '%' . $search . '%');
         });
     })->orWhere(function ($query) use($search) {
         $query->whereHas('manufacturer', function ($query) use($search) {
             $query->where('name', 'LIKE', '%' . $search . '%');
         });
     });
 }
コード例 #3
0
 /**
  * Group an array based on one of it's values.
  *
  * @method  scopeArrayGrouped
  *
  * @param Illuminate\Database\Query\Builder $query     The query being scoped
  * @param string                            $group_key The key whose value we'll group by
  *
  * @return array The grouped array
  */
 public function scopeArrayGrouped($query, $key_column)
 {
     // First get the results from the query
     $results = $query->get();
     // Initialise an empty array to store our results in
     $rtn = [];
     /** @var Illuminate\Database\Eloquent\Model $result */
     foreach ($results as $result) {
         $group_key = $result->{$key_column};
         // If the group key has not already been set in our results,
         // initialise it as an empty array
         if (!isset($rtn[$group_key])) {
             $rtn[$group_key] = [];
         }
         // Add the model to the query
         $rtn[$group_key][] = $result;
     }
     return $rtn;
 }
コード例 #4
0
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     return $query->where(function ($query) use($search) {
         $query->where('title', 'LIKE', '%' . $search . '%')->orWhere('notes', 'LIKE', '%' . $search . '%')->orWhere('asset_maintenance_type', 'LIKE', '%' . $search . '%')->orWhere('cost', 'LIKE', '%' . $search . '%')->orWhere('start_date', 'LIKE', '%' . $search . '%')->orWhere('completion_date', 'LIKE', '%' . $search . '%');
     });
 }
コード例 #5
0
ファイル: Asset.php プロジェクト: jbirdkerr/snipe-it
 /**
  * Query builder scope to order on location
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $order       Order
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  * TODO: Extend this method out for checked out assets as well. Right now it
  * only checks the location name related to rtd_location_id
  */
 public function scopeOrderLocation($query, $order)
 {
     return $query->join('locations', 'locations.id', '=', 'assets.rtd_location_id')->orderBy('locations.name', $order);
 }
コード例 #6
0
ファイル: User.php プロジェクト: stijni/snipe-it
 /**
  * Query builder scope to order on company
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $order         Order
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeOrderLocation($query, $order)
 {
     return $query->leftJoin('locations', 'users.location_id', '=', 'locations.id')->orderBy('locations.name', $order);
 }
コード例 #7
0
ファイル: Message.php プロジェクト: rafaelvieiras/connect
 /**
  * Get the unread notifications for a user.
  *
  * @param Illuminate\Database\Query\Builder $query
  * @param int $userId (Default: null)
  *
  * @return Illuminate\Database\Query\Builder
  */
 public function scopeUnreadReceiver($query, $userId = null)
 {
     if (empty($userId)) {
         $userId = \Sentry::getUser()->id;
     }
     return $query->where(function (\Illuminate\Database\Query\Builder $query) use($userId) {
         $query->where('read', '=', 0)->where('to_user_id', $userId);
     });
 }
コード例 #8
0
ファイル: DbStore.php プロジェクト: mreschke/repository
 /**
  * Add group by to query builder
  * @param Illuminate\Database\Query\Builder $query object is by reference
  */
 protected function addGroupByQuery($query)
 {
     if (isset($this->groupBy)) {
         foreach ($this->groupBy as $groupBy) {
             $query->groupBy($groupBy);
         }
     }
 }
コード例 #9
0
ファイル: Location.php プロジェクト: chromahoen/snipe-it
 /**
  * Query builder scope to order on parent
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $order    	 Order
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeOrderParent($query, $order)
 {
     // Left join here, or it will only return results with parents
     return $query->leftJoin('locations as parent_loc', 'locations.parent_id', '=', 'parent_loc.id')->orderBy('parent_loc.name', $order);
 }
コード例 #10
0
ファイル: Model.php プロジェクト: lucabro81/esempio_api
 /**
  * Filter the joined table of the query by the value passed in $filters
  *
  * @author Luca Brognara
  * @date December 2015
  *
  * @param Illuminate\Database\Query\Builder $query
  * @param string 							 $model
  * @param array 							 $filters
  * @param string 							 $filters
  *
  * @return array
  */
 public function scopeFilterBy($query, $model, $filters, $table)
 {
     if (count($filters) == 0) {
         return $query;
     }
     return $query->whereHas($model, function ($query) use($filters, $table) {
         try {
             $this->filter($query, $filters, $this->get_table_columns($table));
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
     });
 }
コード例 #11
0
ファイル: User.php プロジェクト: Jarby-dev/snipe-it
 /**
  * Query builder scope to order on manager
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $order    	 Order
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeOrderManager($query, $order)
 {
     // Left join here, or it will only return results with parents
     return $query->leftJoin('users as manager', 'users.manager_id', '=', 'manager.id')->orderBy('manager.first_name', $order)->orderBy('manager.last_name', $order);
 }
コード例 #12
0
ファイル: testRandomLib.php プロジェクト: zhangzijun/diandian
// 创建链接
$capsule->addConnection($database, 'seed');
// 设置全局静态可访问
$capsule->setAsGlobal();
$table = 't_crm_soa_order';
// 启动Eloquent
$capsule->bootEloquent();
$conn = $capsule->getConnection('seed');
$grammar = $conn->getQueryGrammar();
$processor = $conn->getPostProcessor();
$sql = "select column_name from information_schema.columns where table_schema = 'gold_db' and table_name =\r\n't_crm_soa_order'";
$sql = 'desc t_crm_soa_order';
//dd($conn->getColumnListing($table));
//$conn->statement();
$ret = $conn->select($sql);
$queryBuilder = new Illuminate\Database\Query\Builder($conn, $grammar, $processor);
//dd($queryBuilder->getColumnListing($table));
dd($ret);
exit;
$conn->affectingStatement();
$conn->commit();
//dd($conn->getColumnListing($table));
//dd($conn->statement('desc t_crm_soa_order'));
dd($queryBuilder->select('desc t_crm_soa_order'));
dd($conn->statement('desc t_crm_soa_order'));
//$ret =Capsule::connection('seed')->table('t_crm_soa_order')->count();
//use App\Lib\BaseModel;
//$model = new BaseModel();
//$model->setConnection('seed');
//$model->setTable('t_crm_soa_order');
//dd($model->newQueryWithoutScopes()->select('desc ' . $model->getTable()));
コード例 #13
0
ファイル: CollectionDelegator.php プロジェクト: CFLOVEYR/hook
 /**
  * Shortcut for get+toJson methods.
  * @param  string $columns columns
  * @return string
  */
 public function toJson($columns = array('*'))
 {
     return $this->query->get($columns)->toJson();
 }
コード例 #14
0
 /**
  * Scope for the last notifications.
  *
  * @param Illuminate\Database\Query\Builder $query
  * @param int $limit (Default: 10)
  *
  * @return Illuminate\Database\Query\Builder
  */
 public function scopeRecent($query, $limit = 10)
 {
     return $query->orderBy('created_at', 'desc')->limit($limit);
 }
コード例 #15
0
 /**
  * Query builder scope to order on admin user
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $order       Order
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeOrderAdmin($query, $order)
 {
     return $query->leftJoin('users', 'asset_maintenances.user_id', '=', 'users.id')->orderBy('users.first_name', $order)->orderBy('users.last_name', $order);
 }
コード例 #16
0
ファイル: License.php プロジェクト: dmeltzer/snipe-it
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     return $query->where(function ($query) use($search) {
         $query->where('name', 'LIKE', '%' . $search . '%')->orWhere('serial', 'LIKE', '%' . $search . '%')->orWhere('notes', 'LIKE', '%' . $search . '%')->orWhere('order_number', 'LIKE', '%' . $search . '%')->orWhere('purchase_date', 'LIKE', '%' . $search . '%')->orWhere('purchase_cost', 'LIKE', '%' . $search . '%');
     });
 }
コード例 #17
0
ファイル: Project.php プロジェクト: rafaelvieiras/connect
 /**
  * Querie all not completed projects
  *
  * @param Illuminate\Database\Query\Builder $query
  *
  * @return Illuminate\Database\Query\Builder
  */
 public function scopeOpen($query)
 {
     return $query->whereNull('completed_at');
 }
コード例 #18
0
ファイル: User.php プロジェクト: rafaelvieiras/connect
 /**
  * Scope for all not activated users.
  *
  * @param Illuminate\Database\Query\Builder $query
  *
  * @return Illuminate\Database\Query\Builder
  */
 public function scopeNotActivated($query)
 {
     return $query->where('activated', '=', 0);
 }
コード例 #19
0
ファイル: Model.php プロジェクト: esensi/core
 /**
  * Builds a query scope to return object alphabetically for a dropdown list.
  *
  * @param Illuminate\Database\Query\Builder $query
  * @param string $column (optional) to order by
  * @param string $key (optional) to use in returned array
  * @param string $sort (optional) direction
  * @return array
  */
 public function scopeListAlphabetically($query, $column = null, $key = null, $sort = 'asc')
 {
     $column = is_null($column) ? $this->getKeyName() : $column;
     return $query->orderBy($column, $sort)->lists($column, $key)->all();
 }
コード例 #20
0
ファイル: Statuslabel.php プロジェクト: dmeltzer/snipe-it
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     return $query->where(function ($query) use($search) {
         $query->where('name', 'LIKE', '%' . $search . '%');
     });
 }
コード例 #21
0
ファイル: Vehicle.php プロジェクト: janusnic/fuellog
 /**
  * Query scope "isAllowed".
  *
  * @param   Illuminate\Database\Query\Builder   $query
  * @return  Illuminate\Database\Query\Builder
  */
 public function scopeIsAllowed($query)
 {
     return $query->whereHas('user', function ($q) {
         return $q->whereId(auth()->id());
     });
 }
コード例 #22
0
ファイル: Model.php プロジェクト: naiwungmusic/snipe-it
 /**
  * Query builder scope for Deleted assets
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeDeleted($query)
 {
     return $query->whereNotNull('deleted_at');
 }
コード例 #23
0
ファイル: RelatingModelTrait.php プロジェクト: Einkoro/model
 /**
  * Set the relationships that should not be eager loaded.
  *
  * @param  Illuminate\Database\Query\Builder $query
  * @param  mixed $relations
  * @return $this
  */
 public function scopeWithout($query, $relations)
 {
     $relations = is_array($relations) ? $relations : array_slice(func_get_args(), 1);
     $relationships = array_dot($query->getEagerLoads());
     foreach ($relations as $relation) {
         unset($relationships[$relation]);
     }
     return $query->setEagerLoads([])->with(array_keys($relationships));
 }
コード例 #24
0
ファイル: Consumable.php プロジェクト: lutherpros/snipe-it
 /**
  * Query builder scope to order on company
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $order    	 Order
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeOrderCompany($query, $order)
 {
     return $query->leftJoin('companies', 'consumables.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
 }
コード例 #25
0
ファイル: Task.php プロジェクト: rafaelvieiras/connect
 /**
  * Scope of all not completed tasks.
  *
  * @param Illuminate\Database\Query\Builder $query
  *
  * @return Illuminate\Database\Query\Builder
  */
 public function scopeNotCompleted($query)
 {
     return $query->where('completed', '=', '0');
 }