wilkques / repositories
Laravel Repository
v2.0.0
2022-08-22 08:22 UTC
Requires
- php: ^7.4|^8.0
- illuminate/database: *
- illuminate/support: *
Suggests
- illuminate/pagination: Required to paginate the result set.
README
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
\Illuminate\Database\Query\Builder
ALL Methods\Illuminate\Database\Eloquent\Model
ALL Methods\Illuminate\Database\Eloquent\Builder
ALL Methods\Illuminate\Database\Eloquent\Collection
ALL Methods\Illuminate\Pagination\LengthAwarePaginator
ALL Methods\Illuminate\Support\Facades\DB
ALL Methods