Giter VIP home page Giter VIP logo

anar's Introduction

Anar

Latest Version on Packagist Total Downloads Build Status StyleCI

Anar is artisan command to create repository for your amazing laravel app easy peasy . Take look at contributing.md to see a to do list.

if you don't know about Repository pattern read this link

Installation

Via Composer

$ composer require amin3520/anar

Change log

Please see the changelog for more information on what has changed recently.

command

$ php artisan make:repository name  --m=model_name --imp 
  #sample php artisan make:repository UserRepository --m=User --imp 
  #sample2 php artisan make:repository UserRepository --m='\App\User' --imp 

name is your name Repository ,

--moption is model name that use in repo and it is necessary input , now u can also pass your address model in string like '\App\User'

--imp create interface for your repo

first run of command create base files and directory ,you can see them below

|--Providers
|       |--RepositoryServiceProvider.php
|
|--Repositories
|       |--BaseRepository.php
|       |--BaseRepositoryImp.php
|       |//and other your repoitorys

Configuration

if you want inject your repositories in some constructor like controllers ,add repo name in $names in Providers/RepositoryServiceProvider.php and add \App\Providers\RepositoryServiceProvider::class in providers in config\app.php

  /**
     * Register RepositoryServiceProvider  .
     * provide your repository and inject it any where below your app directoy, like in to your controller's app if you want to use it
     * @return void
     */
    public function register()
    {
         $names = [
               //add Begin your repository name here   like -> 'UserRepository',
            ];

            foreach ($names as $name) {
                $this->app->bind(
                    "App\\Repositories\\{$name}",
                    "App\\Repositories\\{$name}");
            }


    }

Usage

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    private $userRepo;

    /**
     * Controller constructor.
     *inject repo by service provider
     */
    public function __construct(UserRepositoryImp $repositoryImp)
    {
        $this->userRepo=$repositoryImp;
        //now u can use it
    }

    public function updateName(Request $request)
    {
        $this->userRepo->update(['name'=>'amin'],auth::id());
    }
}

BaseMethods

Base repository has some useful method you can use theme

interface BaseRepositoryImp
{
        public function create(array $attributes);
        public function update(array $attributes, int $id);
        public function all($columns = array('*'), string $orderBy = 'id', string $sortBy = 'desc');
        public function find(int $id);
        public function findOneOrFail(int $id);
        public function findBy(array $data);
        public function findOneBy(array $data);
        public function findOneByOrFail(array $data);
        public function paginateArrayResults(array $data, int $perPage = 50);
        public function delete(int $id);
        public function findWhere($where, $columns = ['*'], $or = false);
        public function with(array $relations);
}

methods

Contributing

Please see contributing.md for details and a todolist.

Task list:

  • add Test
  • add dynamic directory option
  • add dynamically pickUp address's model
  • add cache option

License

MIT License. Please see the license file for more information.

anar's People

Contributors

amin3536 avatar freakpants avatar dependabot[bot] avatar stylecibot avatar

Stargazers

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