3.3.5 2023-12-28 13:00 UTC


Latest Version Software License Build Status Coverage Status Total Downloads


A base repository class for Eloquent with convenience methods that cover most queries. Useful to abstract away your persistence layer from your business code.

Dedicated to Genie

Dedicated to the World's best (and only) Genie in a bottle. Congrats on the freedom my man.


For Laravel 5.4 and above

composer require optimus/genie ~2.0

For Laravel 5.3 and below

composer require optimus/genie ~1.0


The examples will use a hypothetical Eloquent model named User.


namespace App\Repositories;

use App\Models\User;
use Optimus\Genie\Repository;

class UserRepository extends Repository
    protected function getModel()
        return new User;


Genie is already integrated with Optimus\Bruno. See Bruno documentation for more information. The $options key given by all get-methods takes the following format:

Parameter Value type Description
includes array Array of relationships to eager load
sort array Array of sorting rules, e.g. [['key' => 'username', 'direction' => 'ASC']]
filter_groups array See Bruno documentation
limit int Rows per page
page int The page to start from (use with limit)

Note: If you use the controller of Bruno it will automatically parse the request's query string into the correct format.


The examples will use a hypothetical Eloquent model named User.

get (array $options = [])

Get all User rows

getById ($id, array $options = [])

Get one User by primary key

getRecent (array $options = [])

Get User rows ordered by created_at descending

getRecentWhere (string $column, mixed $value, array $options = [])

Get User rows where $column=$value, ordered by created_at descending

getWhere (string $column, mixed $value, array $options = [])

Get User rows where $column=$value

getWhereArray (array $clauses, array $options = [])

Get User rows by multiple where clauses ([$column1 => $value1, $column2 => $value2])

getWhereIn (string $column, array $values, array $options = [])

Get User rows where $column can be any of the values given by $values

getLatest (array $options = [])

Get the most recent User

getLatestWhere (string $column, mixed $value, array $options = [])

Get the most recent User where $column=$value

delete ($id)

Delete User rows by primary key

deleteWhere ($column, $value)

Delete User rows where $column=$value

deleteWhereArray (array $clauses)

Delete User rows by multiple where clauses ([$column1 => $value1, $column2 => $value2])


This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.


$ phpunit


Please see CONTRIBUTING for details.


The MIT License (MIT). Please see License File for more information.