Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miladimos/laravel-repository
Laravel / Lumen Repository pattern [Alpha version]
https://github.com/miladimos/laravel-repository
laravel laravel-helpers laravel-package laravel-repositories laravel-repository laravel-repository-pattern lumen-package lumen-repository-pattern repository-pattern repository-pattern-maker
Last synced: 2 days ago
JSON representation
Laravel / Lumen Repository pattern [Alpha version]
- Host: GitHub
- URL: https://github.com/miladimos/laravel-repository
- Owner: miladimos
- Created: 2020-08-31T11:32:33.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-21T15:46:36.000Z (about 1 year ago)
- Last Synced: 2024-04-22T11:45:13.841Z (7 months ago)
- Topics: laravel, laravel-helpers, laravel-package, laravel-repositories, laravel-repository, laravel-repository-pattern, lumen-package, lumen-repository-pattern, repository-pattern, repository-pattern-maker
- Language: PHP
- Homepage:
- Size: 112 KB
- Stars: 11
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
- [![Starts](https://img.shields.io/github/stars/miladimos/laravel-repository?style=flat&logo=github)](https://github.com/miladimos/laravel-repository/forks)
- [![Forks](https://img.shields.io/github/forks/miladimos/laravel-repository?style=flat&logo=github)](https://github.com/miladimos/laravel-repository/stargazers)### in your project
`composer require miladimos/laravel-repository`
### for install package
`php artisan repository:install`
### for create new repository
`php artisan make:repository {ModelName}`
### Example:
`php artisan make:repository Tag`
this create a TagRepository and TagEloquentRepositoryInterface
next you must add Repository to RepositoryServiceProvider in repositories property like:
```php
protected $repositories = [
[
TagEloquentRepositoryInterface::class,
TagRepository::class,
],
];
```next in your controller add this:
```php
private $tagRepo;
public function __construct(TagEloquentRepositoryInterface $tagRepo)
{
$this->tagRepo = $tagRepo;
}```
add custom methods in TagEloquentRepositoryInterface and implement them.
you must have a provider with below content and register it:
```php
repositories as $repository) {
$this->app->bind($repository[0], $repository[1]);
}
}
}
```or create it automatically by below command:
```php
php artisan make:repository:provider
```and add to app.php providers:
```php
App\Providers\RepositoryServiceProvider::class,
```#### Methods:
```php
$model->all($columns = ['*']);$model->create(array $data);
$model->update(array $data, $id, $attribute = "id");
$model->find($id);
$model->findOrFail($id);
$model->findWhere(string $field, $condition, $columns);
$model->first();
$model->last();
$model->firstOrCreate();
$model->whereIn($attribute, array $values);
$model->max($column);
$model->min($column);
$model->avg($column);
$model->delete($id);
$model->truncate();
$model->count($columns = ['*']);
$model->paginate($columns = ['*'], $perPage = 8);
$model->simplePaginate($limit = null, $columns = ['*']);
$model->search(array $query, $columns = ["*"]);
$model->pluck($value, $key = null);
$model->with($relations);
$model->toSql();
```