All Projects → akunbeben → laravository

akunbeben / laravository

Licence: MIT license
Simplified Repository pattern implementation in Laravel

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravository

GraphQL.RepoDB
A set of extensions for working with HotChocolate GraphQL and Database access with micro-orms such as RepoDb (or Dapper). This extension pack provides access to key elements such as Selections/Projections, Sort arguments, & Paging arguments in a significantly simplified facade so this logic can be leveraged in the Serivces/Repositories that enca…
Stars: ✭ 25 (+78.57%)
Mutual labels:  repository, repository-pattern
baserepo
Base repository
Stars: ✭ 71 (+407.14%)
Mutual labels:  repository, repository-pattern
eloquent-repository
Repository pattern for Eloquent ORM with focus in cache.
Stars: ✭ 30 (+114.29%)
Mutual labels:  repository, repository-pattern
BetterRepository
Better Enhanced Repository Pattern Implementation in .NET C#
Stars: ✭ 27 (+92.86%)
Mutual labels:  repository, repository-pattern
Onion Architecture Asp.net Core
WhiteApp API solution template which is built on Onion Architecture with all essential feature using .NET 5!
Stars: ✭ 196 (+1300%)
Mutual labels:  repository, repository-pattern
Hexagonal-architecture-ASP.NET-Core
App generator API solution template which is built on Hexagnonal Architecture with all essential feature using .NET Core
Stars: ✭ 57 (+307.14%)
Mutual labels:  repository, repository-pattern
laravel-repository
Repository pattern implementation for Laravel
Stars: ✭ 49 (+250%)
Mutual labels:  repository, repository-pattern
Android Architecture Components
The template project that uses Android Architecture Components with Repository pattern. The simple app that uses awesome Fuel library instead of Retrofit for perfoming HTTP request. The app also persists data using the Room library and display data in RecyclerView.
Stars: ✭ 329 (+2250%)
Mutual labels:  repository, repository-pattern
Model
Ruby persistence framework with entities and repositories
Stars: ✭ 399 (+2750%)
Mutual labels:  repository, repository-pattern
receptacle
minimalistic implementation of the repository pattern
Stars: ✭ 18 (+28.57%)
Mutual labels:  repository, repository-pattern
laravel-repository-pattern
Files autogenerator for repositorry pattern
Stars: ✭ 46 (+228.57%)
Mutual labels:  repository, repository-pattern
meta-git
git plugin for meta
Stars: ✭ 22 (+57.14%)
Mutual labels:  repository
weedow-searchy
Automatically exposes web services over HTTP to search for Entity-related data using a powerful query language
Stars: ✭ 21 (+50%)
Mutual labels:  repository
Building-a-Node-Express.js-Rest-API-server-using-a-repository-pattern
A complete example of a Node + Express.js rest api server
Stars: ✭ 45 (+221.43%)
Mutual labels:  repository-pattern
issuer-icons
Vector graphics of one-time password issuer logo's, used in Raivo OTP for iOS.
Stars: ✭ 79 (+464.29%)
Mutual labels:  repository
gsrd
GitHub Starred Repos Downloader
Stars: ✭ 23 (+64.29%)
Mutual labels:  repository
Asmin
Asmin is .NET CORE project infrastructure, to get a quick start on the project.
Stars: ✭ 89 (+535.71%)
Mutual labels:  repository-pattern
grepo
GKISS - A fork of KISS Linux that uses the GNU C library, mirror of https://codeberg.org/kiss-community/grepo
Stars: ✭ 51 (+264.29%)
Mutual labels:  repository
copybara-action
Transform and move code between repositories. Start with ZERO config and 100% customizable.
Stars: ✭ 69 (+392.86%)
Mutual labels:  repository
QuerySpecification
Abstract package for building query specifications in your domain model.
Stars: ✭ 18 (+28.57%)
Mutual labels:  repository

Laravository - Repository Pattern for Laravel

Simplified Repository pattern implementation in Laravel.

Requirement

  • Laravel 8.x

Installation

Execute the following command to get the latest version of the package:

composer require akunbeben/laravository

Execute the following command to create the RepositoryServiceProvider:

php artisan repository:provider

Go to the config/app.php and add this App\Providers\RepositoryServiceProvider::class to your providers config:

The RepositoryServiceProvider will work as Dependency Injection.

'providers' => [
  ...
  App\Providers\RepositoryServiceProvider::class,
],

Methods

Akunbeben\Laravository\Repositories\Interfaces

  • getAll();
  • getById($id, $relations = null)
  • create($attributes)
  • update($id, $attributes)
  • delete($id)

Usage

Create a new Repository

To create repository, you just need to run like this:

php artisan make:repository User

You can also add -m or --model option to generate the Model:

php artisan make:repository User -m

So you don't need to create Model manually.

You can find out the generated files under the App\Repositories\ folder:

  • Repository: App\Repositories\Eloquent\
  • Interface: App\Repositories\Interfaces\

UserRepository.php

namespace App\Repositories\Eloquent;

use Akunbeben\Laravository\Repositories\Eloquent\BaseRepository;

use App\Repositories\Interfaces\UserRepositoryInterface;
use App\Models\User;

class UserRepository extends BaseRepository implements UserRepositoryInterface
{
  protected $model;

  /**
   * Your model to use the Eloquent
   * 
   * @param User $model
   */
  public function __construct(User $model)
  {
    $this->model = $model;
  }
}

UserRepositoryInterface.php

namespace App\Repositories\Interfaces;

interface UserRepositoryInterface
{
    
}

After you created the repositories. you need to register your Class and Interface in the RepositoryServiceProvider.php

...
class RepositoryServiceProvider extends ServiceProvider
{
  ...
  public function register()
  {
    ...
    $this->app->bind(UserRepositoryInterface::class, UserRepository::class);
  }
}

Now you can implement it to your Controller. Like this example below:

namespace App\Http\Controllers;

use App\Repositories\Interfaces\UserRepositoryInterface;

class UserController extends Controller
{
  protected $userRepository;

  public function __construct(UserRepositoryInterface $userRepository) {
    $this->userRepository = $userRepository;
  }
}

So your Controller will much cleaner and much shorter.

class UserController extends Controller
{
  protected $userRepository;

  public function __construct(UserRepositoryInterface $userRepository) {
    $this->userRepository = $userRepository;
  }

  ...

  public function store(SomeFormRequest $request)
  {
    return $this->userRepository->create($request->validated());
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].