Skip to content

Commit dd5460c

Browse files
committed
Use app() helper function instead of inject Application Container using constructor
1 parent cf04e16 commit dd5460c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Repositories/Repository.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use ReflectionClass;
66

7-
use Illuminate\Container\Container as App;
8-
97
use Illuminate\Database\Eloquent\Model;
108
use Illuminate\Contracts\Routing\UrlRoutable;
119

@@ -57,9 +55,8 @@ abstract class Repository implements RepositoryContract, UrlRoutable
5755
* @param \Illuminate\Database\Eloquent\Model $model
5856
* @return void
5957
*/
60-
public function __construct(App $app) {
61-
$this->app = $app;
62-
58+
public function __construct() {
59+
// Initialize Repository Instance
6360
$this->initializeRepository();
6461
}
6562

@@ -158,14 +155,20 @@ public function model() {
158155
* @throws PPSpaces\Exceptions\RepositoryException
159156
*/
160157
public function initializeRepository() {
158+
// Loading application instance
159+
$this->app = app();
160+
161+
// Making model
161162
$model = $this->app->make($this->model);
162163

163164
if (!$model instanceof Model) {
164165
throw new RepositoryException("Class {$this->model} must be an instance of Illuminate\\Database\\Eloquent\\Model");
165166
}
166167

168+
// Create repository model query
167169
$this->repository = $model->newQuery();
168170

171+
// Inject before scope
169172
$this->before($this->repository);
170173
}
171174

@@ -215,6 +218,6 @@ public function __toString()
215218
return $this->resolved->toJson();
216219
}
217220

218-
return null;
221+
return $this->get()->toJson();
219222
}
220223
}

0 commit comments

Comments
 (0)