2017 © Pedro Peláez
 

library genie

image

faisalrizal/genie

  • Sunday, March 4, 2018
  • by faisalrizal
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 14 Forks
  • 0 Open issues
  • 18 Versions
  • 0 % Grown

The README.md

Genie

Latest Version Software License Total Downloads Build Status, (*1)

Introduction

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

Dedicated to Genie, (*3)

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

Installation

composer require faisalrizal/genie

Implementation

The examples will use a hypothetical Eloquent model named User., (*5)

<?php

namespace App\Repositories;

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

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

Options

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:, (*6)

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., (*7)

API

The examples will use a hypothetical Eloquent model named User., (*8)

get (array $options = [])

Get all User rows, (*9)

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

Get one User by primary key, (*10)

getRecent (array $options = [])

Get User rows ordered by created_at descending, (*11)

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

Get User rows where $column=$value, ordered by created_at descending, (*12)

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

Get User rows where $column=$value, (*13)

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

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

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

Get User rows where $column can be any of the values given by $values, (*15)

getLatest (array $options = [])

Get the most recent User, (*16)

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

Get the most recent User where $column=$value, (*17)

delete ($id)

Delete User rows by primary key, (*18)

deleteWhere ($column, $value)

Delete User rows where $column=$value, (*19)

deleteWhereArray (array $clauses)

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

Standards

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

Testing

bash $ phpunit, (*22)

Contributing

Please see CONTRIBUTING for details., (*23)

License

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

The Versions