Download the PHP package inquiloper/laravel-baserepository without Composer
On this page you can find all versions of the php package inquiloper/laravel-baserepository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download inquiloper/laravel-baserepository
More information about inquiloper/laravel-baserepository
Files in inquiloper/laravel-baserepository
Package laravel-baserepository
Short Description A base repository that wraps some of laravel eloquent's functionality so you can share it among your own repositories.
License MIT
Informations about the package laravel-baserepository
Laravel Base Repository
Description
A wrapper around eloquent's main features so you can share them among your own repositories
Installation
In order to install this package, all you have to do is execute the following line in your console
composer require inquiloper/laravel-baserepository
Then in your repositories
That's it, you're ready to rock now!
Documentation
Let's suppose you have this function in your controller where you type-hint your repo
public function users(UsersRepositoryInterface $usersRepo){}
Now, the methods you have available are:
Find all elements of the model
$usersRepo->findAll()
Find one element by $field
$usersRepo->findOneBy(Array $fields)
Find All elements by $fields
$usersRepo->findAllBy(Array $fields)
Create and save to the DB
$usersRepo->create(Array $data)
Update with $data by $fields
$usersRepo->updateBy(Array $fields, Array $data)
public function with($relationships);
Update with $data by $fields
$usersRepo->updateBy(Array $fields, Array $data)
Delete by $fields
$usersRepo->deleteBy(Array $fields)
Eager-load relationships
$usersRepo->with(['posts', 'comments'])->findOneBy(['id' => 1])
Dynamic methods
You can call the findOneBy method with a dynamic name like so:
$usersRepo->findOneByName('John Doe')
This will translate to select * from users where name = 'John Doe' limit 1
The dynamic calling will automatically snake_case anything after findOneBy , so Name converts to name, UserEmail to user_email and so on. You can turn this off and the method will add the where clause with the literal name
$usersRepo->findOneByWpEmail('[email protected]' , false)
This will translate to select * from users where WpEmail = '[email protected]' limit 1