From 1ae8f12544435e5e6d616e2944051ffccb0ae256 Mon Sep 17 00:00:00 2001 From: Yish Date: Tue, 13 Aug 2019 01:31:46 +0800 Subject: [PATCH] Update README.md --- README.md | 288 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 236 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 518ae84..abb84e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -

+# Laravel Oh Generators -

+

Build Status Total Downloads Latest Stable Version @@ -8,99 +8,283 @@ License

-# Laravel Oh Generators - -> This package extends the core file generators that are included with Laravel 5 / 6 +This package extends the core file generators that are included with Laravel 5 / 6 -[Docs site](https://packages.yish.dev/packages/laravel-oh-generator.html) +## Requirement +#### PHP >= 7 +#### Laravel >= 5 +- 5.4 before using branch `1.1.x` +- 5.5 ~ 5.7 using branch `2.0.x` +- 5.8 or later using branch `2.1.x` -# Installation +## Installation -Install by composer -``` - $ composer require yish/generators +Install via composer +``` bash +$ composer require yish/generators ``` -* 5.4 before using branch `1.1.x` -* 5.5 ~ 5.7 using branch `2.0.x` -* 5.8 or later using branch `2.1.x` +#### Registing Service Provider -Registing Service Provider +If you are using laravel 5.5 or later, you can use auto discover, you don't need put in service provider to `app.php`. -If you are using laravel 5.5, you can use auto discover also, you don't need put in service provider to `app.php`. +``` php + [ + \Yish\Generators\GeneratorsServiceProvider::class, +], +``` +## Generating Service +It can be generating class service. +``` bash +$ php artisan make:service UserService +``` ``` php [ - \Yish\Generators\GeneratorsServiceProvider::class, - ], +class UserService +{ + protected $repository; + // +} +``` +Also, it supports abstract service. +You should inject your repository or model and then use it. +``` php +all() +create($attributes) +first() +firstBy($column, $value) +find($id) +findBy($column, $value) +get() +getBy($column, $value) +update($id, $attributes) +updateBy($column, $value, $attributes) +destroy($id) +destroyBy($column, $value) +paginate($page = 12) +paginateBy($column, $value, $page = 12) ``` -## Example +## Generating Repository +It can be generating class repository. +``` bash +$ php artisan make:repository UserRepository +``` +``` php + It can be generating class service. +class UserRepository +{ + protected $model; + // +} ``` - $ php artisan make:service UserService +Also, it supports abstract repository. +You should inject your model and then use it. +``` php +all($columns = ['*']) +create($attributes) +update($id, array $attributes, array $options = []) +updateBy($column, $value, array $attributes = [], array $options = []) +first($columns = ['*']) +firstBy($column, $value, $columns = ['*']) +find($id, $columns = ['*']) +findBy($column, $value, $columns = ['*']) +get($columns = ['*']) +getBy($column, $value, $columns = ['*']) +destroy($ids) +destroyBy($column, $value) +paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) +paginateBy($column, $value, $perPage = null, $columns = ['*'], $pageName = 'page', $page = null) ``` -* Supported: - * [Abstract Service](https://github.com/Mombuyish/Laravel-Oh-Generators/wiki/Abstract-Service) +## Generating Transformer +It can be generating class transformer. +``` bash +$ php artisan make:transformer UserTransformer +``` +### Support +#### TransformContract +``` php + Transformer class. +// $attributes => Need transform data, maybe array or collection etc. +transformer(UserTransformer::class, $data); +``` -### Generating Repository: ->It can be generating class repository. +## Generating Formatter +It can be generating class formatter. +``` bash +$ php artisan make:formatter UserFormatter +``` +``` php + It can be generating class transformer. +use Illuminate\Http\Request; +use Yish\Generators\Foundation\Format\FormatContract; +use Yish\Generators\Foundation\Format\Statusable; +class PostFormatter implements FormatContract +{ + use Statusable; + + protected $status = true; +} ``` - $ php artisan make:transformer UserTransformer -``` +If not, you can set `false` to get failed format. +``` php + It can be generating class formatter. +use Illuminate\Http\Request; +use Yish\Generators\Foundation\Format\FormatContract; +use Yish\Generators\Foundation\Format\Statusable; +class PostFormatter implements FormatContract +{ + use Statusable; + + protected $status = false; +} ``` - $ php artisan make:formatter UserFormatter +If you need customize message, you can do: +``` php + It can be generating class presenter. +class Success extends Formatter implements FormatContract +{ + use Statusable; + protected $status = false; + + public function code() + { + return Response::HTTP_ACCEPTED; + } +} ``` - $ php artisan make:presenter UserPresenter +If you need to customize what you need, check out `Yish\Generators\Foundation\Format\Statusable` get more detail. + +#### Helper / formatter() +``` php +// $request => Must instance of `Illuminate\Http\Request`. +// $instance => Formatter class. +// $items => data. +formatter(request(), UserFormatter::class, $data); ``` -### Generating Foundation -> It can be generating class foundation. +## Generating Presenter +It can be generating class presenter. +``` bash +$ php artisan make:presenter UserPresenter +``` +``` php +