Skip to content

Commit b0ffeb2

Browse files
committed
2.0.0-a.1
1 parent 408302b commit b0ffeb2

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

src/Contracts/Parser.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function parseIncludeParams(): void
8787
$withs[$with] = $this->setWithQuery($where, $fields);
8888
}
8989

90-
$this->repository->with($withs);
90+
$this->builder->with($withs);
9191
}
9292

9393
/**
@@ -114,7 +114,7 @@ protected function parseSortParams(): void
114114
continue;
115115
}
116116

117-
$this->repository->orderBy($sortF, $sortD);
117+
$this->builder->orderBy($sortF, $sortD);
118118
}
119119

120120
if ($withSorts->count() > 0) {
@@ -130,7 +130,7 @@ protected function parseJoinSorts(Collection $sorts)
130130
return $currentTable.'.'.$field;
131131
}, $this->parseFieldParams());
132132

133-
$this->repository->select($fields);
133+
$this->builder->select($fields);
134134

135135
foreach ($sorts as $sortF => $sortD) {
136136
[$with, $key] = explode('.', $sortF);
@@ -153,8 +153,8 @@ protected function parseJoinSorts(Collection $sorts)
153153

154154
$withTableName = strpos($withTable, '.') === false ? $withConnection.'.'.$withTable : $withTable;
155155

156-
$this->repository->leftJoin($withTableName, "{$withTableName}.{$foreignKey}", "{$currentTable}.{$localKey}");
157-
$this->repository->orderBy("{$withTableName}.{$key}", $sortD);
156+
$this->builder->leftJoin($withTableName, "{$withTableName}.{$foreignKey}", "{$currentTable}.{$localKey}");
157+
$this->builder->orderBy("{$withTableName}.{$key}", $sortD);
158158
}
159159
}
160160

@@ -197,7 +197,7 @@ protected function parseFilterParams(): void
197197
} elseif (! in_array($whr['key'], $tableColumns)) {
198198
continue;
199199
}
200-
$this->setQueryBuilderWhereStatement($this->repository, $table.'.'.$whr['key'], $whr);
200+
$this->setQueryBuilderWhereStatement($this->builder, $table.'.'.$whr['key'], $whr);
201201
}
202202
}
203203

@@ -215,7 +215,7 @@ protected function setWhereHasClause(array $where): void
215215
}
216216
$subKey = $sub->qualifyColumn($key);
217217

218-
$this->repository->whereHas(Helpers::camel($with), function ($q) use ($where, $subKey) {
218+
$this->builder->whereHas(Helpers::camel($with), function ($q) use ($where, $subKey) {
219219
$this->setQueryBuilderWhereStatement($q, $subKey, $where);
220220
});
221221
}

src/Contracts/Relationships.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function storeRelated($item, array $includes, array $data): void
8989
$type = class_basename(get_class($relation));
9090
$relatedRecords = $data[Helpers::snake($with)];
9191

92-
$this->repository->with($with);
92+
$this->builder->with($with);
9393

9494
switch ($type) {
9595
case 'HasOne':

src/Http/Api/Contracts/HasModel.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ trait HasModel
1616
*/
1717
protected static $model;
1818

19+
/**
20+
*
21+
* @var \Illuminate\Database\Eloquent\Builder
22+
*/
23+
protected $builder;
24+
1925
/**
2026
* Do we need to unguard the model before create/update?
2127
*
@@ -49,6 +55,8 @@ protected function makeModel(): void
4955
}
5056

5157
self::$model = $model;
58+
59+
$this->builder = $model->newQuery();
5260
}
5361

5462
/**

src/Http/Api/Contracts/HasPolicies.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected function qualifyCollectionQuery(): void
1616
$modelPolicy = Gate::getPolicyFor(self::$model);
1717

1818
if ($modelPolicy && method_exists($modelPolicy, 'qualifyCollectionQueryWithUser')) {
19-
$modelPolicy->qualifyCollectionQueryWithUser($user, $this->repository);
19+
$modelPolicy->qualifyCollectionQueryWithUser($user, $this->builder);
2020
}
2121
}
2222

@@ -31,7 +31,7 @@ protected function qualifyItemQuery(): void
3131
$modelPolicy = Gate::getPolicyFor(self::$model);
3232

3333
if ($modelPolicy && method_exists($modelPolicy, 'qualifyItemQueryWithUser')) {
34-
$modelPolicy->qualifyItemQueryWithUser($user, $this->repository);
34+
$modelPolicy->qualifyItemQueryWithUser($user, $this->builder);
3535
}
3636
}
3737

src/Http/Api/Contracts/HasRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ trait HasRepository
1515

1616
/**
1717
* Creates our repository linkage.
18+
*
19+
* @deprecated
1820
*/
1921
protected function makeRepository()
2022
{

src/Http/Api/Contracts/HasResources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function parseAllowedScopes($request): void
8383

8484
if ($request->has($snake) || $request->has($camel)) {
8585
$value = $this->parseScopeValue($request->has($snake) ? $request->get($snake) : $request->get($camel));
86-
call_user_func([$this->repository, $camel], $value);
86+
call_user_func([$this->builder, $camel], $value);
8787
}
8888
}
8989
}

src/Http/Api/Controller.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ abstract class Controller extends BaseController
6969
public function __construct()
7070
{
7171
$this->makeModel();
72-
$this->makeRepository();
72+
// $this->makeRepository();
7373
}
7474

7575
/**
@@ -85,7 +85,7 @@ public function handleIndexAction($request = null, array $extraParams = [])
8585
$fields = $this->parseFieldParams();
8686
$limit = $this->parseLimitParams();
8787

88-
$items = $limit > 0 ? $this->repository->paginate($limit, $fields)->appends($this->originalQueryParams) : $this->repository->get($fields);
88+
$items = $limit > 0 ? $this->builder->paginate($limit, $fields)->appends($this->originalQueryParams) : $this->builder->get($fields);
8989

9090
return $this->handleIndexResponse($items);
9191
}
@@ -97,7 +97,7 @@ public function handleIndexActionRaw($request = null, array $extraParams = [])
9797
$fields = $this->parseFieldParams();
9898
$limit = $this->parseLimitParams();
9999

100-
$items = $limit > 0 ? $this->repository->paginateRaw($limit, $fields)->appends($this->originalQueryParams) : $this->repository->getRaw($fields);
100+
$items = $limit > 0 ? $this->builder->paginateRaw($limit, $fields)->appends($this->originalQueryParams) : $this->builder->getRaw($fields);
101101

102102
return $this->handleIndexResponse($items);
103103
}
@@ -189,7 +189,7 @@ public function handleShowAction($id, $request = null, array $extraParams = [])
189189
$this->qualifyItemQuery();
190190

191191
try {
192-
$item = $this->repository->find($id, $fields);
192+
$item = $this->builder->find($id, $fields);
193193
$this->authoriseUserAction('view', $item);
194194
} catch (ModelNotFoundException $exception) {
195195
return $this->errorNotFound('Record not found');
@@ -213,7 +213,7 @@ public function handleUpdateAction($id, $request, array $extraParams = [])
213213
$this->handleCommonActions($request);
214214

215215
try {
216-
$item = $this->repository->find($id);
216+
$item = $this->builder->find($id);
217217
$this->authoriseUserAction('update', $item);
218218
} catch (ModelNotFoundException $exception) {
219219
return $this->errorNotFound('Record does not exist');
@@ -263,7 +263,7 @@ public function handleDestroyAction($id, $request = null)
263263
$this->qualifyItemQuery();
264264

265265
try {
266-
$item = $this->repository->find($id);
266+
$item = $this->builder->find($id);
267267
$this->authoriseUserAction('delete', $item);
268268
$item->delete();
269269
} catch (ModelNotFoundException $exception) {

0 commit comments

Comments
 (0)