GithubHelp home page GithubHelp logo

dy05 / laravel-repository-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lab2view/laravel-repository-generator

0.0 0.0 0.0 26 KB

Generating repositories from existing model files

PHP 100.00%

laravel-repository-generator's Introduction

Laravel Repositories generator

Latest Stable Version Total Downloads Monthly Downloads License

Laravel Repositories Generator is a package for Laravel used to generate repositories from Eloquent models.

Installation

Run the following command from your terminal:

composer require "lab2view/laravel-repository-generator"

Usage

Generate repository classes from Eloquent models in the Models folder:

php artisan make:repositories

Use the generated repository in the controller:

<?php namespace App\Http\Controllers;

use App\Repositories\PostRepository;

class PostController extends Controller {

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

    public function index() {
        return response()->json($this->postRepository->getAll());
    }
}

Available Methods

The following methods are available:

Lab2view\RepositoryGenerator\RepositoryInterface
    public function exists(string $key, $value, $withTrashed = false)

    public function getByAttribute(string $attr_name, $attr_value, $relations = [], $withTrashed = false, $selects = [])

    public function getPaginate(int $n, $relations = [], $withTrashed = false, $selects = []);

    public function store(Array $inputs)

    public function getById($id, $relations = [], $withTrashed = false, $selects = [])

    public function search($key, $value, $relations = [], $withTrashed = false, $selects = [])

    public function getAll($relations = [], $withTrashed = false, $selects = [])

    public function countAll($withTrashed = false)

    public function getAllSelectable($key)

    public function update($id, Array $inputs)

    public function destroy($id)

    public function destroyAll()

    public function forceDelete($id)

    public function restore($id)

Example usage

Create a new post in repository:

$post = $this->postRepository->store($request->all());

Update an existing post:

$post = $this->postRepository->update($post_id, $request->all());

Delete post:

$post = $this->postRepository->destroy($id);

Get a post by post_id:

$post = $this->postRepository->getById($id);

you can also choose what relations to eager load:

$post = $this->postRepository->getById($id, ['comments']);

Contributing

Thank you for considering contributing to this Laravel package.

Credits

This package is inspired by this great package by @bosnadev.

laravel-repository-generator's People

Contributors

dy05 avatar sajaddp avatar tcharod 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.