Skip to content
master
Switch branches/tags
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Oct 18, 2021
src
Oct 23, 2021
Oct 23, 2021
Aug 25, 2021
Oct 18, 2021

Laravel Repository

Laravel Version Support

  • ^5.5 ^6.0 ^7.0 ^8.0

Php Version Support

  • ^7.0 ^8.0

Latest Stable Version Total Downloads Latest Unstable Version License

Daily Downloads Monthly Downloads Total Downloads

Issues Stars Forks

Table of Contents

Installation

Composer

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

composer require jetbox/laravel-repository

Repository Install

php artisan repository:install

Create Repository

Create a new Eloquent model repository class

php artisan make:repository UserRepository

Methods

JetBox\Repositories\Contracts\RepositoryInterface

  • get($columns = ['*'], $take = false, $pagination = false, $where = false);
  • all($columns = ['*']);
  • take($take, $columns = ['*']);
  • paginate($perPage = false, $columns = ['*']);
  • withPaginate($relations, $columns = ['*'], $paginate = 15);
  • simplePaginate($perPage = false, $columns = ['*']);
  • limit($take, $columns = ['*']);
  • find($id, $columns = ['*']);
  • findMany($ids, $columns = ['*']);
  • findOrFail($id, $columns = ['*']);
  • first($columns = ['*']);
  • firstOrFail($columns = ['*']);
  • where($column, $value = null, $columns = ['*']);
  • whereOrFail($column, $value = null, $columns = ['*']);
  • whereAll($column, $value = null, $columns = ['*']);
  • whereWithAll($column, $value = null, $relations, $columns = ['*']);
  • whereBetween($column, $value = [], $columns = ['*']);
  • with($relations, $columns = ['*']);
  • withCount($relations, $columns = ['*']);
  • pluck($column, $key = null);
  • create(array $attributes);
  • forceCreate(array $attributes);
  • update(array $attributes, $model, bool $tap = false, bool $forceFill = false);
  • updateForce(array $attributes, $model, bool $tap = false);
  • delete($model, bool $tap = false, bool $forceDelete = false);
  • forceDelete($model, bool $tap = false);
  • querySortable(string $orderByColumn, string $orderByDirection)

Helpers

  • lLog(string $message, string $log = 'info', array $context = [], string $disk = null)
  • is_json(string $str, bool $returnData = false)
  • currentUser(): ?Authenticatable
  • getWebsiteName(): string
  • getWebsiteUrl(): string

Usage

Create a Repository

Recommended This Shorter

Laravel ^5.7 ^6.0 ^7.0 ^8.0 if your model is not linked to the repository auto, you can override the $model property of your repository

namespace App\Repositories;

class UserRepository extends AbstractRepository
{

}

Or

Laravel ^5.2 <=5.6 override the $model property

namespace App\Repositories;

use App\Models\User;

class UserRepository extends AbstractRepository
{
    /**
     * @var string
     */
    protected $model = User::class;

   /**
    * Global OrderBy Column
    * @var string
    */
   public $orderByColumn = 'created_at';

   /**
    * Global OrderBy Direction
    * @var string
    */
   public $orderByDirection = 'desc';
}

Use methods

namespace App\Http\Controllers;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
use App\Repositories\UserRepository as UserR;

class UserController extends BaseController {

    /**
     * @var $users
     */
    protected $users;

    /**
    * UserController constructor.
    * @param UserR $users
    */
    public function __construct(UserR $users)
    {
        $this->users = $users;
    }

    /**
    * @return Application|Factory|View
    */
    public function index()
    {
        $users = $this->users->all();

        return view('users', compact('users'));
    }

}

Find all results in Repository

$users = $this->users->all();

Find by result by id

$user = $this->users->find($id);

About

Laravel Repository Package

Resources

Packages

No packages published

Languages