From 78c1ae17d4a7cb50cf62c427a4fe27c49b115f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Tesoura=20J=C3=BAnior?= Date: Sun, 17 Oct 2021 12:22:44 -0300 Subject: [PATCH] Refactor/vic laravel template (#19) * feat(repository): add updated_at to default filters * refactor(resource): generate base request * feat(seed): add environment verification * refactor(request): change store prepareForValidation from replace to merge * refactor(request): change update prepareForValidation from replace to merge * 1.2.9: app version --- .../laravel/app/Http/Requests/__name__StoreRequest.php.txt | 2 +- .../laravel/app/Http/Requests/__name__UpdateRequest.php.txt | 2 +- .../laravel/app/Http/Resources/__name__Resource.php.txt | 4 +--- .../laravel/app/Repositories/__name__Repository.php.txt | 4 ++-- .../laravel/database/seeders/__name__Seeder.php.txt | 5 ++++- package.json | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/templates/laravel/app/Http/Requests/__name__StoreRequest.php.txt b/app/templates/laravel/app/Http/Requests/__name__StoreRequest.php.txt index 5a4dfc1..28e6d96 100644 --- a/app/templates/laravel/app/Http/Requests/__name__StoreRequest.php.txt +++ b/app/templates/laravel/app/Http/Requests/__name__StoreRequest.php.txt @@ -13,7 +13,7 @@ class <%= namePascal %>StoreRequest extends CoreRequest */ protected function prepareForValidation() { - return $this->replace([ + return $this->merge([ // ]); } diff --git a/app/templates/laravel/app/Http/Requests/__name__UpdateRequest.php.txt b/app/templates/laravel/app/Http/Requests/__name__UpdateRequest.php.txt index 8eb51c4..3059095 100644 --- a/app/templates/laravel/app/Http/Requests/__name__UpdateRequest.php.txt +++ b/app/templates/laravel/app/Http/Requests/__name__UpdateRequest.php.txt @@ -13,7 +13,7 @@ class <%= namePascal %>UpdateRequest extends CoreRequest */ protected function prepareForValidation() { - return $this->replace([ + return $this->merge([ // ]); } diff --git a/app/templates/laravel/app/Http/Resources/__name__Resource.php.txt b/app/templates/laravel/app/Http/Resources/__name__Resource.php.txt index b806568..d164190 100644 --- a/app/templates/laravel/app/Http/Resources/__name__Resource.php.txt +++ b/app/templates/laravel/app/Http/Resources/__name__Resource.php.txt @@ -14,8 +14,6 @@ class <%= namePascal %>Resource extends JsonResource */ public function toArray($request) { - return [ - // - ]; + return parent::toArray($request); } } diff --git a/app/templates/laravel/app/Repositories/__name__Repository.php.txt b/app/templates/laravel/app/Repositories/__name__Repository.php.txt index 88b8057..e8b3513 100644 --- a/app/templates/laravel/app/Repositories/__name__Repository.php.txt +++ b/app/templates/laravel/app/Repositories/__name__Repository.php.txt @@ -23,7 +23,7 @@ class <%= namePascal %>Repository extends CoreRepository * Allowed model columns to use in sort * @var array */ - protected $allow_order = array('created_at'); + protected $allow_order = array('created_at','updated_at'); /** * Allowed model columns to use in query search @@ -35,7 +35,7 @@ class <%= namePascal %>Repository extends CoreRepository * Allowed model columns to use in filter by date * @var array */ - protected $allow_between_dates = array('created_at'); + protected $allow_between_dates = array('created_at','updated_at'); /** * Allowed model columns to use in filter by value diff --git a/app/templates/laravel/database/seeders/__name__Seeder.php.txt b/app/templates/laravel/database/seeders/__name__Seeder.php.txt index 91a1a36..a688e6b 100644 --- a/app/templates/laravel/database/seeders/__name__Seeder.php.txt +++ b/app/templates/laravel/database/seeders/__name__Seeder.php.txt @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\<%= namePascal %>; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\App; class <%= namePascal %>Seeder extends Seeder { @@ -14,6 +15,8 @@ class <%= namePascal %>Seeder extends Seeder */ public function run() { - <%= namePascal %>::factory(1)->create(); + if (App::environment('local')) { + <%= namePascal %>::factory(1)->create(); + } } } diff --git a/package.json b/package.json index 31111dd..6da3fc9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-secjs", - "version": "1.2.8", + "version": "1.2.9", "description": "🧬 Generator for any NodeJS Project or Framework", "main": "app/index.js", "scripts": {