All Projects → recca0120 → Laravel Repository

recca0120 / Laravel Repository

Licence: mit
Repository Design Pattern for Laravel 5 with Eloquent or Collection

Projects that are alternatives of or similar to Laravel Repository

Laravel Repositories
[ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
Stars: ✭ 664 (+509.17%)
Mutual labels:  laravel, repository
Config
Manage Laravel configuration by persistent storage
Stars: ✭ 139 (+27.52%)
Mutual labels:  laravel, repository
Repository
🖖Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any kind of filters.
Stars: ✭ 134 (+22.94%)
Mutual labels:  laravel, repository
Warehouse
Artesãos Warehouse - A simple and direct approach to repositories!
Stars: ✭ 87 (-20.18%)
Mutual labels:  laravel, repository
Helpers
A collection of Javascript String and Array helpers for Laravel developers
Stars: ✭ 108 (-0.92%)
Mutual labels:  laravel
Validatorjs
A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
Stars: ✭ 1,534 (+1307.34%)
Mutual labels:  laravel
Llum
Llum (light in catalan language) illuminates your Laravel projects speeding up your Github/Laravel development workflow
Stars: ✭ 107 (-1.83%)
Mutual labels:  laravel
Laravel Cacheable
Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
Stars: ✭ 107 (-1.83%)
Mutual labels:  laravel
Laravel Translations Loader
Webpack loader to import Laravel translation files (PHP or JSON) into your JS bundle as JSON.
Stars: ✭ 109 (+0%)
Mutual labels:  laravel
Dlaravel
Laravel and Docker
Stars: ✭ 108 (-0.92%)
Mutual labels:  laravel
Nova Chartjs
A Simple Dashboard Chart in Laravel Nova using Chart JS. Starting create your own dashboard with Chart JS Integration can save your time and help you maintain consistency across standard elements such as Bar, Stacked, Line, Area, Doughnut and Pie Chart.
Stars: ✭ 108 (-0.92%)
Mutual labels:  laravel
Laracom
Laravel FREE E-Commerce Software
Stars: ✭ 1,570 (+1340.37%)
Mutual labels:  laravel
Nova Indicator Field
A colour-coded indicator field for Laravel Nova
Stars: ✭ 108 (-0.92%)
Mutual labels:  laravel
Purifier
HTMLPurifier for Laravel 5/6/7/8
Stars: ✭ 1,537 (+1310.09%)
Mutual labels:  laravel
Kongqi laravel admin
快速laravel后台管理系统,集成了,图片上传,多图上传,批量Excel导入,批量插入,修改,添加,搜索,权限管理RBAC,验证码,插件一个综合完善后台,助你开发快人一步。
Stars: ✭ 109 (+0%)
Mutual labels:  laravel
Docs.spatie.be Old
Code of docs.spatie.be
Stars: ✭ 107 (-1.83%)
Mutual labels:  laravel
Ssg
The official Statamic 3 static site generator package
Stars: ✭ 107 (-1.83%)
Mutual labels:  laravel
Townhouse
[WORK IN PROGRESS] A Multitenancy package for Laravel that keeps each tenant in a separate database.
Stars: ✭ 108 (-0.92%)
Mutual labels:  laravel
Awesome Laravel
A curated list of bookmarks, packages, tutorials, videos and other cool resources from the Laravel ecosystem
Stars: ✭ 10,643 (+9664.22%)
Mutual labels:  laravel
Laravel Excel
🚀 Supercharged Excel exports and imports in Laravel
Stars: ✭ 10,417 (+9456.88%)
Mutual labels:  laravel

Repository Design Pattern for Laravel

StyleCI Build Status Total Downloads Latest Stable Version Latest Unstable Version License Monthly Downloads Daily Downloads Scrutinizer Code Quality Code Coverage

Install

To get the latest version of Laravel Exceptions, simply require the project using Composer:

composer require recca0120/repository

Instead, you may of course manually update your require block and run composer update if you so choose:

{
    "require": {
        "recca0120/repository": "~2.0.0"
    }
}

Methods

Recca0120\Repository\EloquentRepository

  • find($id, $columns = ['*']);
  • findMany($ids, $columns = ['*']);
  • findOrFail($id, $columns = ['*']);
  • findOrNew($id, $columns = ['*']);
  • firstOrNew(array $attributes, array $values = []);
  • firstOrCreate(array $attributes, array $values = []);
  • updateOrCreate(array $attributes, array $values = []);
  • firstOrFail($criteria = [], $columns = ['*']);
  • create($attributes);
  • forceCreate($attributes);
  • update($id, $attributes);
  • forceUpdate($id, $attributes);
  • delete($id);
  • forceDelete($id);
  • newInstance($attributes = [], $exists = false);
  • get($criteria = [], $columns = ['*']);
  • chunk($criteria, $count, callable $callback);
  • each($criteria, callable $callback, $count = 1000);
  • first($criteria = [], $columns = ['*']);
  • paginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null);
  • simplePaginate($criteria = [], $perPage = null, $columns = ['*'], $pageName = 'page', $page = null);
  • count($criteria = [], $columns = '*');
  • min($criteria, $column);
  • max($criteria, $column);
  • sum($criteria, $column);
  • avg($criteria, $column);
  • average($criteria, $column);
  • matching($criteria);
  • getQuery($criteria = []);
  • getModel();
  • newQuery();

Recca0120\Repository\Criteria

  • static create()
  • static expr($value)
  • static raw($value)
  • select($columns = ['*'])
  • selectRaw($expression, array $bindings = [])
  • selectSub($query, $as)
  • addSelect($column)
  • distinct()
  • from($table)
  • join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
  • joinWhere($table, $first, $operator, $second, $type = 'inner')
  • leftJoin($table, $first, $operator = null, $second = null)
  • leftJoinWhere($table, $first, $operator, $second)
  • rightJoin($table, $first, $operator = null, $second = null)
  • rightJoinWhere($table, $first, $operator, $second)
  • crossJoin($table, $first = null, $operator = null, $second = null)
  • mergeWheres($wheres, $bindings)
  • tap($callback)
  • where($column, $operator = null, $value = null, $boolean = 'and')
  • orWhere($column, $operator = null, $value = null)
  • whereColumn($first, $operator = null, $second = null, $boolean = 'and')
  • orWhereColumn($first, $operator = null, $second = null)
  • whereRaw($sql, $bindings = [], $boolean = 'and')
  • orWhereRaw($sql, array $bindings = [])
  • whereIn($column, $values, $boolean = 'and', $not = false)
  • orWhereIn($column, $values)
  • whereNotIn($column, $values, $boolean = 'and')
  • orWhereNotIn($column, $values)
  • whereNull($column, $boolean = 'and', $not = false)
  • orWhereNull($column)
  • whereNotNull($column, $boolean = 'and')
  • whereBetween($column, array $values, $boolean = 'and', $not = false)
  • orWhereBetween($column, array $values)
  • whereNotBetween($column, array $values, $boolean = 'and')
  • orWhereNotBetween($column, array $values)
  • orWhereNotNull($column)
  • whereDate($column, $operator, $value = null, $boolean = 'and')
  • orWhereDate($column, $operator, $value)
  • whereTime($column, $operator, $value, $boolean = 'and')
  • orWhereTime($column, $operator, $value)
  • whereDay($column, $operator, $value = null, $boolean = 'and')
  • whereMonth($column, $operator, $value = null, $boolean = 'and')
  • whereYear($column, $operator, $value = null, $boolean = 'and')
  • whereNested(Closure $callback, $boolean = 'and')
  • addNestedWhereQuery($query, $boolean = 'and')
  • whereExists(Closure $callback, $boolean = 'and', $not = false)
  • orWhereExists(Closure $callback, $not = false)
  • whereNotExists(Closure $callback, $boolean = 'and')
  • orWhereNotExists(Closure $callback)
  • addWhereExistsQuery(Builder $query, $boolean = 'and', $not = false)
  • dynamicWhere($method, $parameters)
  • groupBy()
  • having($column, $operator = null, $value = null, $boolean = 'and')
  • orHaving($column, $operator = null, $value = null)
  • havingRaw($sql, array $bindings = [], $boolean = 'and')
  • orHavingRaw($sql, array $bindings = [])
  • orderBy($column, $direction = 'asc')
  • orderByDesc($column)
  • latest($column = 'created_at')
  • oldest($column = 'created_at')
  • inRandomOrder($seed = '')
  • orderByRaw($sql, $bindings = [])
  • skip($value)
  • offset($value)
  • take($value)
  • limit($value)
  • forPage($page, $perPage = 15)
  • forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
  • union($query, $all = false)
  • unionAll($query)
  • lock($value = true)
  • lockForUpdate()
  • sharedLock()
  • when($value, $callback, $default = null)
  • unless($value, $callback, $default = null)
  • whereKey($id)
  • whereKeyNot($id)
  • with($relations)
  • without($relations)
  • setQuery($query)
  • setModel(Model $model)
  • has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
  • orHas($relation, $operator = '>=', $count = 1)
  • doesntHave($relation, $boolean = 'and', Closure $callback = null)
  • whereHas($relation, Closure $callback = null, $operator = '>=', $count = 1)
  • orWhereHas($relation, Closure $callback = null, $operator = '>=', $count = 1)
  • whereDoesntHave($relation, Closure $callback = null)
  • withCount($relations)
  • mergeConstraintsFrom(Builder $from)
  • withTrashed()
  • withoutTrashed()
  • onlyTrashed()

Usage

Eloquent

Create a Model

Create your model normally, but it is important to define the attributes that can be filled from the input form data.

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $fillable = [
        'title',
        'author',
     ];
}

Create a Contract

namespace App\Repositories\Contracts;

interface PostRepository
{

}

Create a Repository

namespace App\Repositories;

use App\Repositories\Contracts\PostRepository as PostRepositoryContract;
use App\Post;
use Recca0120\Repository\EloquentRepository;

class PostRepository extends EloquentRepository implements PostRepositoryContract
{
    public function __construct(Post $model)
    {
        $this->model = $model;
    }
}

Bind

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Repositories\Contracts\PostRepository as PostRepositoryContract;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(PostRepositoryContract::class, PostRepository::class);
    }
}

Controller

namespace App\Http\Controllers;

use App\Repositories\Contracts\PostRepository;

class PostsController extends Controller
{
    protected $repository;

    public function __construct(PostRepository $repository)
    {
        $this->repository = $repository;
    }
}

Methods

Find all results in Repository

$posts = $this->repository->get();

Find all results in Repository with pagination

$posts = $this->repository->paginate();

Count results in Repository

$posts = $this->repository->count();

Create new entry in Repository

$post = $this->repository->create(request()->all());

Update entry in Repository

$post = $this->repository->update($id, request()->all());

Delete entry in Repository

$this->repository->delete($id);

New instance

$post = $this->repository->newInstance([
    'author' => 'author'
]);

Return Model With Conditions

$model = $this->repository->matching(Criteria::create()->where('title', '=', 'title'));

Find result by id

$post = $this->repository->find($id);

Find by conditions

Using the Criteria

Criteria is support all of Eloquent functions

Single Criteria
use Recca0120\Repository\Criteria;

$criteria = Criteria::create()
    ->select('*')
    ->where('author', '=', 'author')
    ->orWhere('title', '=', 'title')
    ->orderBy('author', 'asc');

$this->repository->get($criteria);
$this->repository->paginate($criteria);

Multiple Criteria

use Recca0120\Repository\Criteria;

$criteria = [];

$criteria[] = Criteria::create()
    ->orderBy('author', 'asc');

$criteria[] = Criteria::create()
    ->where('author', '=', 'author')
    ->orWhere('title', '=', 'title');

$this->repository->get($criteria);
// $this->repository->paginate($criteria);
With
use Recca0120\Repository\Criteria;

$criteria = Criteria::create()
    ->with('author', function($criteria) {
        $criteria->where('author', 'author');
    });

$this->repository->get($criteria);
// $this->repository->paginate($criteria);

Join

use Recca0120\Repository\Criteria;

$criteria = Criteria::create()
    ->join('author', function ($criteria) {
        $criteria->on('posts.author_id', '=', 'author.id');
    });

$this->repository->get($criteria);
// $this->repository->paginate($criteria);

Expression

use Recca0120\Repository\Criteria;

$criteria = Criteria::create()
    ->where('created_at', '<=', Criteria::expr('NOW()'));

$this->repository->get($criteria);
// $this->repository->paginate($criteria);

Custom Criteria

use Recca0120\Repository\Criteria;

class CustomCriteria extends Criteria
{
    public function __construct($id)
    {
        $this->where('id', '=', $id);
    }
}

$this->repository->get((new CustomCriteria(1))->where('autor', 'autor'));

ToDo

  • Cache
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].