Giter Site home page Giter Site logo

trinhphuong / genie Goto Github PK

View Code? Open in Web Editor NEW

This project forked from esbenp/genie

1.0 1.0 0.0 23 KB

A base repository class for Eloquent to abstract away persistence layer from your business code

Home Page: http://optimus.rocks/

License: MIT License

PHP 100.00%

genie's Introduction

Genie

Latest Version Software License Build Status Coverage Status Total Downloads

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.

Dedicated to Genie

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

Installation

For Laravel 5.4 and above

composer require phuongtt/genie ~2.0

For Laravel 5.3 and below

composer require phuongtt/genie ~1.0

Implementation

The examples will use a hypothetical Eloquent model named User.

<?php

namespace App\Repositories;

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

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

Options

Genie is already integrated with Phuongtt\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.

API

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])

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.

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

License

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

genie's People

Contributors

esbenp avatar carghaez avatar boonstoppel avatar skazza94 avatar manandhar avatar quyenhd avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.