本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::newQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::newQuery方法的具体用法?PHP Model::newQuery怎么用?PHP Model::newQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::newQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addEagerConstraints
/**
* Set the constraints for an eager load of the relation.
*
* @param array $models
*
* @return void
*/
public function addEagerConstraints(array $models)
{
$this->query->whereNested(function (Builder $inner) use($models) {
// We will use this query in order to apply constraints to the
// base query builder
$outer = $this->parent->newQuery();
foreach ($models as $model) {
$outer->setQuery($inner)->orWhereDescendantOf($model);
}
});
}
示例2: make
/**
* Make a new instance of the entity to query on.
*
* @param \Illuminate\Database\Eloquent\Builder $with
*/
public function make(array $with = [])
{
if (method_exists($this->model, 'translations')) {
if (!in_array('translations', $with)) {
$with[] = 'translations';
}
}
return $this->model->newQuery()->with($with);
}
示例3: newQuery
/**
* @return Builder
*/
public function newQuery()
{
if (is_string($this->modelClass)) {
return (new $this->modelClass())->newQuery();
}
if ($this->modelClass instanceof Model) {
return $this->modelClass->newQuery();
}
return $this->modelClass;
}
示例4: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$grid = new Grid((new GridConfig())->setDataProvider(new EloquentDataProvider($this->userModel->newQuery()))->setColumns([(new FieldConfig('name', 'Логин'))->setCallback(function ($value, $vl) {
return link_to_route('admin.user.edit', $value, $vl->getSrc());
})->setSortable(true)->addFilter((new FilterConfig())->setOperator(FilterConfig::OPERATOR_LIKE)), (new FieldConfig('email'))->setSortable(true)->addFilter((new FilterConfig())->setOperator(FilterConfig::OPERATOR_EQ)), (new FieldConfig('created_at', 'Дата создания'))->setSortable(true)->setCallback(function (\Carbon\Carbon $value) {
return $value->toDateString();
})->addFilter((new FilterConfig())->setOperator(FilterConfig::OPERATOR_LIKE)), (new FieldConfig('roles', 'Роли'))->setCallback(function ($value) {
$list = $value->lists('display_name');
if (version_compare(app()->version(), '5.1.0', '>=')) {
$list = $list->all();
}
return implode(', ', $list);
})]));
return view('adminPanel::user.index', compact('grid'));
}
示例5: __construct
public function __construct(Model $model)
{
$this->model = $model;
$this->query = $model->newQuery();
$this->parser = new DefaultParser();
$this->introspector = new EloquentPathIntrospector($this->parser);
}
示例6: newQuery
public function newQuery()
{
$query = parent::newQuery();
if ($this->includes) {
return $query->with($this->includes);
}
return $query;
}
示例7: newQuery
public function newQuery($ordered = true)
{
$query = parent::newQuery();
if (empty($ordered)) {
return $query;
}
return $query->orderBy('weight', 'ASC');
}
示例8: newQuery
/**
* Get a new query builder for the model.
* set any type of scope you want on this builder in a child class, and it'll
* keep applying the scope on any read-queries on this model
*
* @return Reposed\Builder
*/
public function newQuery($excludeDeleted = true)
{
$builder = parent::newQuery($excludeDeleted);
if ($this->isSubType()) {
$builder->where($this->typeField, $this->getClass($this->typeField));
}
return $builder;
}
示例9: newQuery
/**
* @return $this|\Illuminate\Database\Eloquent\Builder
*/
public function newQuery()
{
$query = parent::newQuery();
if (substr(\Request::path(), 0, 6) !== 'admin/') {
return $query->where('is_active', 1);
}
return $query;
}
示例10: newQuery
public function newQuery($excludeDeleted = true)
{
$raw = '';
foreach ($this->geofields as $column) {
$raw .= ' astext(' . $column . ') as ' . $column . ' ';
}
return parent::newQuery($excludeDeleted)->addSelect('*', DB::raw($raw));
}
示例11: applyFilters
/**
* Apply order and search filters.
*
* @return Datagrid
* @throws \Exception
*/
public function applyFilters()
{
$this->validate();
$query = $this->searchInEveryColumn($this->model->newQuery());
$query->orderBy($this->orderBy['column'], $this->orderBy['type']);
$this->itens = $query->paginate($this->paginate);
return $this;
}
示例12: search
/**
* @param JsonApiRequest $request
* @return Paginator|Collection|Model|Response|null
*/
protected function search(JsonApiRequest $request)
{
if (!$this->search) {
return $this->notImplemented();
}
$builder = $this->model->newQuery();
return $this->search->search($builder, $request->getParameters());
}
示例13: newQuery
public function newQuery($excludeDeleted = true)
{
$builder = parent::newQuery($excludeDeleted);
if (get_class($this) !== $this->getStiBaseClass()) {
$builder->where($this->getStiClassField(), '=', get_class($this));
}
return $builder;
}
示例14: newQuery
/**
* Redefined for STI pattern
*
* @return mixed
*/
public function newQuery() {
$builder = parent::newQuery();
if ($this->sti_field) {
$builder->where($this->sti_field, get_class($this));
}
return $builder;
}
示例15: newQuery
public function newQuery($excludeDeleted = true)
{
$class = get_called_class();
$query = parent::newQuery($excludeDeleted);
if ($class != 'App\\Post') {
$query->where($this->table . '.model', '=', $class);
}
return $query;
}