Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: about 2 months ago
JSON representation

Laravel / Lumen Repository pattern [Alpha version]

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();

```