wilkques/repositories

Laravel Repository

v2.0.0 2022-08-22 08:22 UTC

This package is auto-updated.

Last update: 2024-11-04 10:15:36 UTC


README

Latest Stable Version License

How to use

composer require wilkques/repositories

example

namespace App\Repositories\UserRepository;

use App\User;
use Wilkques\Repositories\Repository;

class UserRepository extends Repository
{
    public function __construct(User $user)
    {
        parent::__construct($user);
    }

    public function whereName(string $name)
    {
        return $this->where("name", $name);
    }
}

// other class

use App\Repositories\UserRepository;
use App\User;

class UserController extends Controller
{
    protected $userRepository;

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

    public function index(Request $request)
    {
        $user = User::where("name", $request->name)->get()->toArray();

        // same

        $user = $this->userRepository->where("name", $request->name)->get()->toArray();

        // same

        $user = $this->userRepository->whereName($request->name)->get()->toArray();
    }
}

Methods

  1. \Illuminate\Database\Query\Builder ALL Methods
  2. \Illuminate\Database\Eloquent\Model ALL Methods
  3. \Illuminate\Database\Eloquent\Builder ALL Methods
  4. \Illuminate\Database\Eloquent\Collection ALL Methods
  5. \Illuminate\Pagination\LengthAwarePaginator ALL Methods
  6. \Illuminate\Support\Facades\DB ALL Methods

Reference

  1. Laravel
  2. Laravel API DOCS