Skip to content

Order By Rand() error #35

Closed
Closed
@RibesAlexandre

Description

@RibesAlexandre

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'] : '');
        })
        ?: '';
    }

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions