Compatibility changes for Laravel 5.4;
This commit is contained in:
parent
ce70a6f1dc
commit
9c721302be
|
@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation as IlluminateRelation;
|
use Illuminate\Database\Eloquent\Relations\Relation as IlluminateRelation;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Nodes\CounterCache\Exceptions\NoCounterCachesFound;
|
use Nodes\CounterCache\Exceptions\NoCounterCachesFoundException;
|
||||||
use Nodes\CounterCache\Exceptions\NoEntitiesFoundException;
|
use Nodes\CounterCache\Exceptions\NoEntitiesFoundException;
|
||||||
use Nodes\CounterCache\Exceptions\NotCounterCacheableException;
|
use Nodes\CounterCache\Exceptions\NotCounterCacheableException;
|
||||||
use Nodes\CounterCache\Exceptions\RelationNotFoundException;
|
use Nodes\CounterCache\Exceptions\RelationNotFoundException;
|
||||||
|
@ -23,7 +23,7 @@ class CounterCache
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Nodes\CounterCache\Exceptions\NoCounterCachesFound
|
* @throws \Nodes\CounterCache\Exceptions\NoCounterCachesFoundException
|
||||||
* @throws \Nodes\CounterCache\Exceptions\NotCounterCacheableException
|
* @throws \Nodes\CounterCache\Exceptions\NotCounterCacheableException
|
||||||
* @throws \Nodes\CounterCache\Exceptions\RelationNotFoundException
|
* @throws \Nodes\CounterCache\Exceptions\RelationNotFoundException
|
||||||
*/
|
*/
|
||||||
|
@ -42,7 +42,7 @@ class CounterCache
|
||||||
// Validate counter caches
|
// Validate counter caches
|
||||||
if (empty($counterCaches)) {
|
if (empty($counterCaches)) {
|
||||||
Log::error(sprintf('[%s] No counter caches found on model [%s].', __CLASS__, get_class($model)));
|
Log::error(sprintf('[%s] No counter caches found on model [%s].', __CLASS__, get_class($model)));
|
||||||
throw new NoCounterCachesFound(sprintf('No counter caches found on model [%s].', __CLASS__, get_class($model)));
|
throw new NoCounterCachesFoundException(sprintf('No counter caches found on model [%s].', __CLASS__, get_class($model)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle each available counter caches
|
// Handle each available counter caches
|
||||||
|
@ -140,8 +140,8 @@ class CounterCache
|
||||||
$countQuery = $model->newQuery()
|
$countQuery = $model->newQuery()
|
||||||
->select(DB::raw(sprintf('COUNT(%s.id)', $model->getTable())))
|
->select(DB::raw(sprintf('COUNT(%s.id)', $model->getTable())))
|
||||||
->join(
|
->join(
|
||||||
DB::raw(sprintf('(SELECT %s.%s FROM %s) as relation', $relationTableName, $relation->getOtherKey(), $relationTableName)),
|
DB::raw(sprintf('(SELECT %s.%s FROM %s) as relation', $relationTableName, $relation->getOwnerKey(), $relationTableName)),
|
||||||
$relation->getQualifiedForeignKey(), '=', sprintf('relation.%s', $relation->getOtherKey())
|
$relation->getQualifiedForeignKey(), '=', sprintf('relation.%s', $relation->getOwnerKey())
|
||||||
)
|
)
|
||||||
->where($relation->getQualifiedForeignKey(), '=', $this->prepareValue($foreignKey));
|
->where($relation->getQualifiedForeignKey(), '=', $this->prepareValue($foreignKey));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue