Closed
Description
Issue
Undefined index Column
Environment
Laravel Version: 5.5.23
Laravel Model Caching Package Version: 0.2.9
PHP Version: 7.0.26
Homestead Version: none
Operating System & Version: name x.y.z
When I use orderByRaw('RAND()') in a model, I get These error. The simple solution is to test if the key exists.
Stack Trace
// vendor/genealabs/laravel-model-caching/src/CacheKey.php
protected function getOrderByClauses() : string
{
$orders = collect($this->query->orders);
return $orders->reduce(function($carry, $order){
return $carry . '_orderBy_' . $order['column'] . '_' . $order['direction'];
})
?: '';
}
Solution :
protected function getOrderByClauses() : string
{
$orders = collect($this->query->orders);
return $orders->reduce(function($carry, $order){
return $carry . '_orderBy_' . (isset($order['column']) ? $order['column'] : '') . '_' . (isset($order['direction']) ? $order['direction'] : '');
})
?: '';
}