bosnadev / repository

Laravel Repositories is a package for Laravel 5 which is used to abstract the database layer. This makes applications much easier to maintain.
https://bosnadev.com
825 stars 235 forks source link

How can I get ordered resultset in child repository? #32

Closed appkr closed 8 years ago

appkr commented 9 years ago

In my child repository...

class ChildRepository extends \Bosnadev\Repositories\Eloquent\Repository
{
    public function model() {}

    public function suggest($column, $search)
    {
        return $this->getByCriteria(new Like($column, $search))
            ->all(['id', \DB::raw("{$column} as name")]);
    }
}

all() returns EloquentCollection, and does not allow additional method chaining.

Before extending this package it was,

    public function suggest($column, $query)
    {
        return $this->model->where($column, 'like', $query . '%')
            ->orderBy($column, 'asc')->get(['id', \DB::raw("{$column} as name")]);
    }

What is the best way I can chain orderBy() with \Bosnadev\Repositories\Eloquent\Repository. Do I have to make a OrderBy Criteria?

fer-ri commented 9 years ago

Maybe put your suggest into new Criteria