tuxboy/laravel-repository

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Allows you to call Eloquent via a repository class

dev-master 2017-12-16 20:09 UTC

This package is auto-updated.

Last update: 2021-09-23 22:27:08 UTC


README

Installtion

$ composer require tuxboy/laravel-repository

And run composer update or composer install -o

Then add Service provider to config/app.php

'providers' => [
    // ...
    \TuxBoy\Repository\RepositoryServiceProvider::class,
];

Quick start

In your project, create a Repository file that is BaseRepository:

namespace App\Repositories;

use App\Models\Ticket;
use TuxBoy\Repository\Repositories\BaseRepository;

class TicketRepository extends BaseRepository
{
    use Sortable;

    /**
     * @var Ticket
     */
    protected $model;

    /**
     * TicketRepository constructor.
     * @param Ticket $ticket
     */
    public function __construct(Ticket $ticket)
    {
        $this->model = $ticket;
    }
}    

So in your controller, you can use it via Laravel DI :

namespace App\Http\Controllers;

use App\Repositories\TicketRepository;

class TicketsController extends Controller
{
    /**
     * @var TicketRepository
     */
    private $ticketRepository;

    public function __construct(TicketRepository $ticketRepository)
    {
        $this->ticketRepository = $ticketRepository;
    }
    
    // ...
}