andersao / andersao/l5-repository
Criteria apply() method receive build as a first parameter instead of model when using with()
- 主要語言
- PHP
- 星號
- 4.2k
- 分支
- 880
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Having this criteria applied in the `boot()` method of the repository:
```php
class LastCreatedCriteria implements CriteriaInterface
{
/**
* Applying descending order based on created_at in query repository
*
* @param $model
* @param RepositoryInterface $repository
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
return $model->orderBy($model->getCreatedAtColumn(), 'DESC');
}
}
```
and a method like this:
```php
public function retrieveWithRelation(int $id)
{
$this->with('relation');
return $this->find($id);
}
```
doing a `dd()` of `$model`, this is the result:
```
Builder {#514
#query: Builder {#398
+connection: MySqlConnection {#188
#pdo: PDOConnection {#468
inTransaction: false
...
```
causing the method `retrieveWithRelation()`to throw an exception:
`Call to undefined method Illuminate\\Database\\Query\\Builder::getCreatedAtColumn()`.
Removing `$this->with('relation');` the method works as excepted.
貢獻指南
評估
這個 Issue 還沒有評估資料。