andersao / andersao/l5-repository

Criteria apply() method receive build as a first parameter instead of model when using with()

Aperta
#423 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
4.2k
Fork
880
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.