Locker\Repository\Lrs\EloquentRepository::index PHP Method

index() public method

Gets all of the available models with the options.
public index ( array $opts ) : [Model]
$opts array
return [Model]
    public function index(array $opts)
    {
        if ($opts['user']->role === 'super') {
            $query = $this->where($opts);
        } else {
            $query = $this->where([])->where('users._id', $opts['user']->_id)->remember(10);
        }
        $obj_result = $query->get()->sortBy(function (Model $model) {
            return strtolower($model->title);
        })->each(function (Model $model) {
            return $this->format($model);
        });
        // Annoying hack to convert stupid Laravel collection object to an array
        // WITHOUT converting the models to associative arrays!!!
        $result = [];
        foreach ($obj_result->getIterator() as $model) {
            $result[] = $model;
        }
        return $result;
    }