Code Monkey home page Code Monkey logo

laravel-repository's Introduction

  • Starts
  • Forks

in your project

composer require miladimos/laravel-repository

for install package

php artisan repository:install

for create new repository

php artisan make:repository {ModelName}

Example:

php artisan make:repository Tag

this create a TagRepository and TagEloquentRepositoryInterface

next you must add Repository to RepositoryServiceProvider in repositories property like:

protected $repositories = [
    [
        TagEloquentRepositoryInterface::class,
        TagRepository::class,
    ],
];

next in your controller add this:

private $tagRepo;
public function __construct(TagEloquentRepositoryInterface $tagRepo)
{
    $this->tagRepo = $tagRepo;
}

add custom methods in TagEloquentRepositoryInterface and implement them.

you must have a provider with below content and register it:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class RepositoryServiceProvider extends ServiceProvider
{

    /**
    * define your repositories here
    */
    protected $repositories = [
        [
            ModelEloquentRepositoryInterface::class,
            ModelRepository::class
        ],
    ];

    public function register()
    {
        foreach ($this->repositories as $repository) {
            $this->app->bind($repository[0], $repository[1]);
        }
    }
}

or create it automatically by below command:

php artisan make:repository:provider

and add to app.php providers:

App\Providers\RepositoryServiceProvider::class,

Methods:

$model->all($columns = ['*']);

$model->create(array $data);

$model->update(array $data, $id, $attribute = "id");

$model->find($id);

$model->findOrFail($id);

$model->findWhere(string $field, $condition, $columns);

$model->first();

$model->last();

$model->firstOrCreate();

$model->whereIn($attribute, array $values);

$model->max($column);

$model->min($column);

$model->avg($column);

$model->delete($id);

$model->truncate();

$model->count($columns = ['*']);

$model->paginate($columns = ['*'], $perPage = 8);

$model->simplePaginate($limit = null, $columns = ['*']);

$model->search(array $query, $columns = ["*"]);

$model->pluck($value, $key = null);

$model->with($relations);

$model->toSql();

laravel-repository's People

Contributors

miladimos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.