Compatibility changes for Laravel 5.4;

This commit is contained in:
Pedro Coutinho 2017-02-16 17:41:01 +00:00
parent ce70a6f1dc
commit 9c721302be
1 changed files with 5 additions and 5 deletions

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model as IlluminateModel;
use Illuminate\Database\Eloquent\Relations\Relation as IlluminateRelation;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Nodes\CounterCache\Exceptions\NoCounterCachesFound;
use Nodes\CounterCache\Exceptions\NoCounterCachesFoundException;
use Nodes\CounterCache\Exceptions\NoEntitiesFoundException;
use Nodes\CounterCache\Exceptions\NotCounterCacheableException;
use Nodes\CounterCache\Exceptions\RelationNotFoundException;
@ -23,7 +23,7 @@ class CounterCache
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return bool
* @throws \Nodes\CounterCache\Exceptions\NoCounterCachesFound
* @throws \Nodes\CounterCache\Exceptions\NoCounterCachesFoundException
* @throws \Nodes\CounterCache\Exceptions\NotCounterCacheableException
* @throws \Nodes\CounterCache\Exceptions\RelationNotFoundException
*/
@ -42,7 +42,7 @@ class CounterCache
// Validate counter caches
if (empty($counterCaches)) {
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
@ -140,8 +140,8 @@ class CounterCache
$countQuery = $model->newQuery()
->select(DB::raw(sprintf('COUNT(%s.id)', $model->getTable())))
->join(
DB::raw(sprintf('(SELECT %s.%s FROM %s) as relation', $relationTableName, $relation->getOtherKey(), $relationTableName)),
$relation->getQualifiedForeignKey(), '=', sprintf('relation.%s', $relation->getOtherKey())
DB::raw(sprintf('(SELECT %s.%s FROM %s) as relation', $relationTableName, $relation->getOwnerKey(), $relationTableName)),
$relation->getQualifiedForeignKey(), '=', sprintf('relation.%s', $relation->getOwnerKey())
)
->where($relation->getQualifiedForeignKey(), '=', $this->prepareValue($foreignKey));