Giter Club home page Giter Club logo

repository's Introduction

This package has been abandoned and is no longer maintained.

Caffeinated Repository

Source License

Getting Started

Introduction

The Caffeinated Repository package allows the means to implement a standard boilerplate repository interface. This covers the standard Eloquent methods in a non-static, non-facade driven way right out of the box. Fear not though Batman! The Caffeinated Repository package does not limit you in any way when it comes to customizing (e.g overriding) the provided interface or adding your own methods.

Installing Caffeinated Repository

It is recommended that you install the package using Composer.

composer require caffeinated/repository

This package is compliant with PSR-1, PSR-2, and PSR-4. If you find any compliance oversights, please send a patch via pull request.

Using Repositories

Create a Model

Create your model like you normally would. We'll be wrapping our repository around our model to access and query the database for the information we need.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model

class Book extends Model
{
    //
}

Create a Repository

Create a new Repository class - usually these classes are simply stored within a Repositories directory. There are a few requirements for each repository instance:

  • Repository classes must extend the Caffeinated EloquentRepository class.
  • Repository classes must specify a public property pointing to the model.
  • Repository classes must specify an array of cache tags. These tags are used by the package to handle automatic cache busting when relevent values change within the database.
<?php

namespace App\Repositories;

use App\Models\Book;
use Caffeinated\Repository\Repositories\EloquentRepository;

class BookRepository extends EloquentRepository
{
    /**
     * @var Model
     */
    public $model = Book::class;

    /**
     * @var array
     */
    public $tag = ['book'];
}

Injecting a Repository

Once you've built and configured your repository instance, you may inject the class within your classes where needed:

<?php

namespace App\Http\Controllers;

use App\Repositories\BookRepository;

class BookController extends Controller
{
    /**
     * @var BookRepository
     */
    protected $book;

    /**
     * Create a new BookController instance.
     *
     * @param  BookRepository  $book
     */
    public function __construct(BookRepository $book)
    {
        $this->book = $book;
    }

    /**
     * Display a listing of all books.
     *
     * @return Response
     */
    public function index()
    {
        $books = $this->book->findAll();

        return view('books.index', compact('books'));
    }
}

repository's People

Contributors

1giba avatar d8vjork avatar jaesung2061 avatar kaidesu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

repository's Issues

5.4

add laravel 5.4?

ErrorException in AbstractRepository.php line 35:

I got this error when trying to get data from database:

Argument 1 passed to Caffeinated\Repository\Eloquent\AbstractRepository::__construct() must implement interface Illuminate\Contracts\Container\Container, none given

Suggestion: Repository::create

Hello,

I think that create method should return only Model, not array of [status, Model], I understand that I can extend this and return only Model, but I think it's confusing, and it should return standard output as Eloquent does.

Is contribution allowed here?

Please Tag a version for Laravel 5.0?

Hi,
I really like the convenience and simplicity of this package.

Would it be possible for you to tag a version for Laravel 5.0/PHP 5.4?

The changes that seem to be required are fairly minimal:

  1. Composer.json
        "php": ">=5.4.0",
        "illuminate/support": "5.0.*",
        "illuminate/config": "5.0.*"
  1. RepositoryServiceProvider.php (replace ::class)
    public function register()
    {
        $this->app->bind('caffeinated.repository.listener', 'Caffeinated\Repository\Listeners\RepositoryEventListener');
    }

It will really help folks like me who are saddled with php 5.4!

Thank you in advance for your time.

can't work on laravel 5.5

Problem 1
- Conclusion: don't install caffeinated/repository v3.1.1
- Conclusion: remove laravel/framework v5.5.8
- Installation request for caffeinated/repository ^3.1 -> satisfiable by caffeinated/repository[v3.1, v3.1.1].
- Conclusion: don't install laravel/framework v5.5.8
- caffeinated/repository v3.1 requires illuminate/config 5.4.* -> satisfiable by illuminate/config[v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9].
- don't install illuminate/config v5.4.0|don't install laravel/framework v5.5.8
- don't install illuminate/config v5.4.13|don't install laravel/framework v5.5.8
- don't install illuminate/config v5.4.17|don't install laravel/framework v5.5.8
- don't install illuminate/config v5.4.19|don't install laravel/framework v5.5.8
- don't install illuminate/config v5.4.27|don't install laravel/framework v5.5.8
- don't install illuminate/config v5.4.36|don't install laravel/framework v5.5.8
- don't install illuminate/config v5.4.9|don't install laravel/framework v5.5.8
- Installation request for laravel/framework (locked at v5.5.8, required as 5.5.*) -> satisfiable by laravel/framework[v5.5.8].

Instructions

Is there any more to using this package with a module?

use

how can i use it?

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.