From c98f56be7d74a4c07df6b57ea94d308dbb449f4a Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Tue, 29 Dec 2020 23:07:18 +0200 Subject: [PATCH 01/11] RestifyJS setup. --- routes/api.php | 5 +++ src/Eager/Related.php | 14 ++++++-- .../Controllers/RestifyJsSetupController.php | 35 +++++++++++++++++++ src/Repositories/Repository.php | 11 ++++++ .../RestifyJsSetupControllerTest.php | 29 +++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/Http/Controllers/RestifyJsSetupController.php create mode 100644 tests/Controllers/RestifyJsSetupControllerTest.php diff --git a/routes/api.php b/routes/api.php index 5dad31bdf..6c32cd672 100644 --- a/routes/api.php +++ b/routes/api.php @@ -19,6 +19,7 @@ use Binaryk\LaravelRestify\Http\Controllers\RepositoryStoreController; use Binaryk\LaravelRestify\Http\Controllers\RepositoryUpdateBulkController; use Binaryk\LaravelRestify\Http\Controllers\RepositoryUpdateController; +use Binaryk\LaravelRestify\Http\Controllers\RestifyJsSetupController; use Illuminate\Support\Facades\Route; // Global Search... @@ -29,6 +30,10 @@ Route::post('/profile', '\\'.ProfileUpdateController::class); Route::post('/profile/avatar', '\\'.ProfileAvatarController::class); + +// RestifyJS +Route::get('/restifyjs/setup', '\\' . RestifyJsSetupController::class); + // Filters Route::get('/{repository}/filters', '\\'.RepositoryFilterController::class); diff --git a/src/Eager/Related.php b/src/Eager/Related.php index b806fea09..2c4fec076 100644 --- a/src/Eager/Related.php +++ b/src/Eager/Related.php @@ -6,7 +6,7 @@ use Binaryk\LaravelRestify\Repositories\Repository; use Binaryk\LaravelRestify\Traits\Make; -class Related +class Related implements \JsonSerializable { use Make; @@ -22,7 +22,7 @@ public function __construct(string $relation, EagerField $field = null) public function isEager(): bool { - return ! is_null($this->field); + return !is_null($this->field); } public function getRelation(): string @@ -34,4 +34,14 @@ public function resolveField(Repository $repository): EagerField { return $this->field->resolve($repository); } + + public function jsonSerialize() + { + return [ + 'relation' => $this->getRelation(), + 'field' => isset($this->field) + ? $this->field->jsonSerialize() + : null + ]; + } } diff --git a/src/Http/Controllers/RestifyJsSetupController.php b/src/Http/Controllers/RestifyJsSetupController.php new file mode 100644 index 000000000..61133c454 --- /dev/null +++ b/src/Http/Controllers/RestifyJsSetupController.php @@ -0,0 +1,35 @@ +json([ + 'config' => $this->config(), + 'repositories' => $this->repositories(), + ]); + } + + private function repositories(): array + { + return collect(Restify::$repositories) + ->map(fn (string $repository) => app($repository)) + ->map(fn (Repository $repository) => $repository->restifyjsSerialize()) + ->all(); + } + + private function config(): array + { + return [ + 'domain' => config('app.url'), + 'base' => Restify::path(), + ]; + } +} diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index c84d00612..215063ecc 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -1075,4 +1075,15 @@ public function isEagerState(): bool { return $this->eagerState === true; } + + public function restifyjsSerialize(): array + { + return [ + 'uriKey' => static::uriKey(), + 'related' => static::getRelated(), + 'sort' => static::sorts(), + 'match' => static::matches(), + 'searchables' => static::searchables(), + ]; + } } diff --git a/tests/Controllers/RestifyJsSetupControllerTest.php b/tests/Controllers/RestifyJsSetupControllerTest.php new file mode 100644 index 000000000..437ff85a0 --- /dev/null +++ b/tests/Controllers/RestifyJsSetupControllerTest.php @@ -0,0 +1,29 @@ +getJson('restifyjs/setup') + ->assertJsonStructure([ + 'config' => [ + 'domain', + 'base', + ], + 'repositories' => [ + [ + 'uriKey', + 'related', + 'sort', + 'match', + 'searchables', + ] + ] + ]) + ->assertOk(); + } +} From fc4a8b746f4d38003d55decf94be533a5dc8a10d Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Tue, 29 Dec 2020 23:07:42 +0200 Subject: [PATCH 02/11] Apply fixes from StyleCI (#345) --- routes/api.php | 3 +-- src/Eager/Related.php | 4 ++-- src/LaravelRestifyServiceProvider.php | 4 ++-- src/Models/ActionLog.php | 9 ++++----- src/Repositories/ActionLogRepository.php | 2 +- src/Repositories/Repository.php | 1 - .../RepositoryUpdateControllerTest.php | 12 ++++++------ .../RestifyJsSetupControllerTest.php | 4 ++-- tests/IntegrationTest.php | 18 ++++++++---------- 9 files changed, 26 insertions(+), 31 deletions(-) diff --git a/routes/api.php b/routes/api.php index 6c32cd672..bc53e7f3a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -30,9 +30,8 @@ Route::post('/profile', '\\'.ProfileUpdateController::class); Route::post('/profile/avatar', '\\'.ProfileAvatarController::class); - // RestifyJS -Route::get('/restifyjs/setup', '\\' . RestifyJsSetupController::class); +Route::get('/restifyjs/setup', '\\'.RestifyJsSetupController::class); // Filters Route::get('/{repository}/filters', '\\'.RepositoryFilterController::class); diff --git a/src/Eager/Related.php b/src/Eager/Related.php index 2c4fec076..e0b9920d1 100644 --- a/src/Eager/Related.php +++ b/src/Eager/Related.php @@ -22,7 +22,7 @@ public function __construct(string $relation, EagerField $field = null) public function isEager(): bool { - return !is_null($this->field); + return ! is_null($this->field); } public function getRelation(): string @@ -41,7 +41,7 @@ public function jsonSerialize() 'relation' => $this->getRelation(), 'field' => isset($this->field) ? $this->field->jsonSerialize() - : null + : null, ]; } } diff --git a/src/LaravelRestifyServiceProvider.php b/src/LaravelRestifyServiceProvider.php index 88c8d3df3..c9a3681ec 100644 --- a/src/LaravelRestifyServiceProvider.php +++ b/src/LaravelRestifyServiceProvider.php @@ -84,7 +84,7 @@ protected function registerPublishing() $migrationFileName = 'create_action_logs_table.php'; if (! $this->migrationFileExists($migrationFileName)) { $this->publishes([ - __DIR__ . "/../database/migrations/{$migrationFileName}" => database_path('migrations/' . date('Y_m_d_His', time()) . '_' . $migrationFileName), + __DIR__."/../database/migrations/{$migrationFileName}" => database_path('migrations/'.date('Y_m_d_His', time()).'_'.$migrationFileName), ], 'restify-migrations'); } @@ -98,7 +98,7 @@ protected function registerPublishing() public static function migrationFileExists(string $migrationFileName): bool { $len = strlen($migrationFileName); - foreach (glob(database_path("migrations/*.php")) as $filename) { + foreach (glob(database_path('migrations/*.php')) as $filename) { if ((substr($filename, -$len) === $migrationFileName)) { return true; } diff --git a/src/Models/ActionLog.php b/src/Models/ActionLog.php index 944b2f5fe..51079c646 100644 --- a/src/Models/ActionLog.php +++ b/src/Models/ActionLog.php @@ -7,7 +7,7 @@ use Illuminate\Support\Str; /** - * Class ActionLog + * Class ActionLog. * @property string batch_id * @property string user_id * @property string name @@ -22,7 +22,6 @@ * @property string original * @property string changes * @property string exception - * @package Binaryk\LaravelRestify\Models */ class ActionLog extends Model { @@ -44,7 +43,7 @@ class ActionLog extends Model public static function forRepositoryStored(Model $model, Authenticatable $user = null, array $dirty = null): self { return new static([ - 'batch_id' => (string)Str::uuid(), + 'batch_id' => (string) Str::uuid(), 'user_id' => optional($user)->getAuthIdentifier(), 'name' => static::ACTION_CREATED, 'actionable_type' => $model->getMorphClass(), @@ -66,7 +65,7 @@ public static function forRepositoryStored(Model $model, Authenticatable $user = public static function forRepositoryUpdated(Model $model, Authenticatable $user = null): self { return new static([ - 'batch_id' => (string)Str::uuid(), + 'batch_id' => (string) Str::uuid(), 'user_id' => optional($user)->getAuthIdentifier(), 'name' => static::ACTION_UPDATED, 'actionable_type' => $model->getMorphClass(), @@ -88,7 +87,7 @@ public static function forRepositoryUpdated(Model $model, Authenticatable $user public static function forRepositoryDestroy(Model $model, Authenticatable $user = null): self { return new static([ - 'batch_id' => (string)Str::uuid(), + 'batch_id' => (string) Str::uuid(), 'user_id' => optional($user)->getAuthIdentifier(), 'name' => static::ACTION_DELETED, 'actionable_type' => $model->getMorphClass(), diff --git a/src/Repositories/ActionLogRepository.php b/src/Repositories/ActionLogRepository.php index d4def683d..36cd295a9 100644 --- a/src/Repositories/ActionLogRepository.php +++ b/src/Repositories/ActionLogRepository.php @@ -14,7 +14,7 @@ public function fields(RestifyRequest $request) return [ field('actionable_type'), - field('actionable_id') + field('actionable_id'), ]; } } diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index 215063ecc..e7601fddf 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -842,7 +842,6 @@ public function detach(RestifyRequest $request, $repositoryId, Collection $pivot public function destroy(RestifyRequest $request, $repositoryId) { $status = DB::transaction(function () use ($request) { - if ($this->resource instanceof ActionLogable) { Restify::actionLog() ->forRepositoryDestroy($this->resource, $request->user()) diff --git a/tests/Controllers/RepositoryUpdateControllerTest.php b/tests/Controllers/RepositoryUpdateControllerTest.php index 95f4a1f44..4de518a95 100644 --- a/tests/Controllers/RepositoryUpdateControllerTest.php +++ b/tests/Controllers/RepositoryUpdateControllerTest.php @@ -23,7 +23,7 @@ public function test_basic_update_works() { $post = factory(Post::class)->create(); - $this->patch('posts/' . $post->id, [ + $this->patch('posts/'.$post->id, [ 'title' => 'Updated title', ])->assertStatus(200); @@ -34,7 +34,7 @@ public function test_put_works() { $post = factory(Post::class)->create(); - $this->withoutExceptionHandling()->put('posts/' . $post->id, [ + $this->withoutExceptionHandling()->put('posts/'.$post->id, [ 'title' => 'Updated title', ])->assertStatus(200); @@ -51,7 +51,7 @@ public function test_unathorized_to_update() $_SERVER['restify.post.update'] = false; - $this->patch('posts/' . $post->id, [ + $this->patch('posts/'.$post->id, [ 'title' => 'Updated title', ])->assertStatus(403) ->assertJson([ @@ -65,7 +65,7 @@ public function test_do_not_update_fields_without_permission() $_SERVER['posts.authorizable.title'] = false; - $response = $this->putJson('post-with-unathorized-fields/' . $post->id, [ + $response = $this->putJson('post-with-unathorized-fields/'.$post->id, [ 'title' => 'Updated title', 'user_id' => 2, ]) @@ -81,7 +81,7 @@ public function test_will_not_update_readonly_fields() $post = factory(Post::class)->create(['image' => null]); - $r = $this->putJson('posts-unauthorized-fields/' . $post->id, [ + $r = $this->putJson('posts-unauthorized-fields/'.$post->id, [ 'user_id' => $user->id, 'image' => 'avatar.png', 'title' => 'Some post title', @@ -108,7 +108,7 @@ public function test_updating_repository_log_action() 'user_id' => $this->authenticatedAs->getAuthIdentifier(), 'name' => ActionLog::ACTION_UPDATED, 'actionable_type' => Post::class, - 'actionable_id' => (string)$post->id + 'actionable_id' => (string) $post->id, ]); $log = ActionLog::latest()->first(); diff --git a/tests/Controllers/RestifyJsSetupControllerTest.php b/tests/Controllers/RestifyJsSetupControllerTest.php index 437ff85a0..8b5e180e0 100644 --- a/tests/Controllers/RestifyJsSetupControllerTest.php +++ b/tests/Controllers/RestifyJsSetupControllerTest.php @@ -21,8 +21,8 @@ public function test_returns_configurations() 'sort', 'match', 'searchables', - ] - ] + ], + ], ]) ->assertOk(); } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 6ff283a66..d8184aac3 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -52,7 +52,7 @@ protected function setUp(): void $this->repositoryMock(); $this->loadMigrations(); $this->loadRoutes(); - $this->withFactories(__DIR__ . '/Factories'); + $this->withFactories(__DIR__.'/Factories'); $this->injectTranslator(); $this->app->bind(ExceptionHandler::class, RestifyHandler::class); @@ -87,7 +87,7 @@ protected function getEnvironmentSetUp($app) 'prefix' => '', ]); - include_once __DIR__ . '/../database/migrations/create_action_logs_table.php'; + include_once __DIR__.'/../database/migrations/create_action_logs_table.php'; (new \CreateActionLogsTable())->up(); } @@ -100,7 +100,7 @@ protected function loadMigrations() { $this->loadMigrationsFrom([ '--database' => 'sqlite', - '--path' => realpath(__DIR__ . DIRECTORY_SEPARATOR . 'Migrations'), + '--path' => realpath(__DIR__.DIRECTORY_SEPARATOR.'Migrations'), ]); } @@ -237,7 +237,7 @@ public function mockUsers($count = 1, $predefinedEmails = []) $i = 0; while ($i < $count) { $users->push(factory(User::class)->create()); - $i ++; + $i++; } foreach ($predefinedEmails as $email) { @@ -262,7 +262,7 @@ public function mockPosts($userId, $count = 1) $users->push(factory(Post::class)->create( ['user_id' => $userId] )); - $i ++; + $i++; } return $users->shuffle(); // randomly shuffles the items in the collection @@ -270,23 +270,21 @@ public function mockPosts($userId, $count = 1) public function getTempDirectory($suffix = ''): string { - return __DIR__ . '/TestSupport/temp' . ($suffix == '' ? '' : '/' . $suffix); + return __DIR__.'/TestSupport/temp'.($suffix == '' ? '' : '/'.$suffix); } public function getMediaDirectory($suffix = ''): string { - return $this->getTempDirectory() . '/media' . ($suffix == '' ? '' : '/' . $suffix); + return $this->getTempDirectory().'/media'.($suffix == '' ? '' : '/'.$suffix); } public function getTestFilesDirectory($suffix = ''): string { - return $this->getTempDirectory() . '/testfiles' . ($suffix == '' ? '' : '/' . $suffix); + return $this->getTempDirectory().'/testfiles'.($suffix == '' ? '' : '/'.$suffix); } public function getTestJpg(): string { return $this->getTestFilesDirectory('test.jpg'); } - - } From 2a527cf0f1c3d81373a0c75550cf3b6b8732954a Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Tue, 29 Dec 2020 23:41:58 +0200 Subject: [PATCH 03/11] wip --- .../Controllers/RestifyJsSetupController.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Http/Controllers/RestifyJsSetupController.php b/src/Http/Controllers/RestifyJsSetupController.php index 61133c454..5857c3994 100644 --- a/src/Http/Controllers/RestifyJsSetupController.php +++ b/src/Http/Controllers/RestifyJsSetupController.php @@ -6,6 +6,7 @@ use Binaryk\LaravelRestify\Restify; use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use Illuminate\Support\Str; class RestifyJsSetupController extends Controller { @@ -20,16 +21,29 @@ public function __invoke(Request $request) private function repositories(): array { return collect(Restify::$repositories) - ->map(fn (string $repository) => app($repository)) - ->map(fn (Repository $repository) => $repository->restifyjsSerialize()) + ->map(fn(string $repository) => app($repository)) + ->map(fn(Repository $repository) => $repository->restifyjsSerialize()) ->all(); } private function config(): array { return [ - 'domain' => config('app.url'), - 'base' => Restify::path(), + 'domain' => $this->deleteFirstAndLastSlash(config('app.url')), + 'base' => $this->deleteFirstAndLastSlash(Restify::path()), ]; } + + private function deleteFirstAndLastSlash(string $domain): string + { + if (Str::startsWith($domain, '/')) { + $domain = Str::replaceFirst('/', '', $domain); + } + + if (Str::endsWith($domain, '/')) { + $domain = Str::replaceLast('/', '', $domain); + } + + return $domain; + } } From 48a08eb28882459e0266975999d88d815ba0b906 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Tue, 29 Dec 2020 23:42:26 +0200 Subject: [PATCH 04/11] Apply fixes from StyleCI (#346) --- src/Http/Controllers/RestifyJsSetupController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Controllers/RestifyJsSetupController.php b/src/Http/Controllers/RestifyJsSetupController.php index 5857c3994..a6144ecd6 100644 --- a/src/Http/Controllers/RestifyJsSetupController.php +++ b/src/Http/Controllers/RestifyJsSetupController.php @@ -21,8 +21,8 @@ public function __invoke(Request $request) private function repositories(): array { return collect(Restify::$repositories) - ->map(fn(string $repository) => app($repository)) - ->map(fn(Repository $repository) => $repository->restifyjsSerialize()) + ->map(fn (string $repository) => app($repository)) + ->map(fn (Repository $repository) => $repository->restifyjsSerialize()) ->all(); } From 57b6480b15851d0d0d8bd5801f6c8d720b18b949 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Wed, 30 Dec 2020 17:33:09 +0200 Subject: [PATCH 05/11] Return actions. --- src/Http/Controllers/RestifyJsSetupController.php | 10 +++++----- src/Repositories/Repository.php | 14 +++++++++----- tests/Controllers/RestifyJsSetupControllerTest.php | 1 + 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Http/Controllers/RestifyJsSetupController.php b/src/Http/Controllers/RestifyJsSetupController.php index 5857c3994..296678978 100644 --- a/src/Http/Controllers/RestifyJsSetupController.php +++ b/src/Http/Controllers/RestifyJsSetupController.php @@ -2,27 +2,27 @@ namespace Binaryk\LaravelRestify\Http\Controllers; +use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; use Binaryk\LaravelRestify\Repositories\Repository; use Binaryk\LaravelRestify\Restify; -use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Str; class RestifyJsSetupController extends Controller { - public function __invoke(Request $request) + public function __invoke(RestifyRequest $request) { return response()->json([ 'config' => $this->config(), - 'repositories' => $this->repositories(), + 'repositories' => $this->repositories($request), ]); } - private function repositories(): array + private function repositories(RestifyRequest $request): array { return collect(Restify::$repositories) ->map(fn(string $repository) => app($repository)) - ->map(fn(Repository $repository) => $repository->restifyjsSerialize()) + ->map(fn(Repository $repository) => $repository->restifyjsSerialize($request)) ->all(); } diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index e7601fddf..dd2fe609e 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -2,6 +2,7 @@ namespace Binaryk\LaravelRestify\Repositories; +use Binaryk\LaravelRestify\Actions\Action; use Binaryk\LaravelRestify\Contracts\ActionLogable; use Binaryk\LaravelRestify\Contracts\RestifySearchable; use Binaryk\LaravelRestify\Controllers\RestResponse; @@ -1075,14 +1076,17 @@ public function isEagerState(): bool return $this->eagerState === true; } - public function restifyjsSerialize(): array + public function restifyjsSerialize(RestifyRequest $request): array { return [ 'uriKey' => static::uriKey(), - 'related' => static::getRelated(), - 'sort' => static::sorts(), - 'match' => static::matches(), - 'searchables' => static::searchables(), + 'related' => static::collectFilters('matches'), + 'sort' => static::collectFilters('sortables'), + 'match' => static::collectFilters('matches'), + 'searchables' => static::collectFilters('searchables'), + 'actions' => $this->resolveActions($request)->filter(fn (Action $action) => $action->isShownOnIndex( + $request, $this + ))->values() ]; } } diff --git a/tests/Controllers/RestifyJsSetupControllerTest.php b/tests/Controllers/RestifyJsSetupControllerTest.php index 8b5e180e0..a7cca7495 100644 --- a/tests/Controllers/RestifyJsSetupControllerTest.php +++ b/tests/Controllers/RestifyJsSetupControllerTest.php @@ -21,6 +21,7 @@ public function test_returns_configurations() 'sort', 'match', 'searchables', + 'actions', ], ], ]) From b8ef4291231c8f2724d2f3b26cb4cec9b332e288 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Wed, 30 Dec 2020 17:33:51 +0200 Subject: [PATCH 06/11] Apply fixes from StyleCI (#347) --- src/Http/Controllers/RestifyJsSetupController.php | 4 ++-- src/Repositories/Repository.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Http/Controllers/RestifyJsSetupController.php b/src/Http/Controllers/RestifyJsSetupController.php index 296678978..d1739bb4e 100644 --- a/src/Http/Controllers/RestifyJsSetupController.php +++ b/src/Http/Controllers/RestifyJsSetupController.php @@ -21,8 +21,8 @@ public function __invoke(RestifyRequest $request) private function repositories(RestifyRequest $request): array { return collect(Restify::$repositories) - ->map(fn(string $repository) => app($repository)) - ->map(fn(Repository $repository) => $repository->restifyjsSerialize($request)) + ->map(fn (string $repository) => app($repository)) + ->map(fn (Repository $repository) => $repository->restifyjsSerialize($request)) ->all(); } diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index dd2fe609e..4afb66c35 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -1086,7 +1086,7 @@ public function restifyjsSerialize(RestifyRequest $request): array 'searchables' => static::collectFilters('searchables'), 'actions' => $this->resolveActions($request)->filter(fn (Action $action) => $action->isShownOnIndex( $request, $this - ))->values() + ))->values(), ]; } } From 347e0bc7118c5f8ccbaab63cf1903d4b0df144f3 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Wed, 30 Dec 2020 19:26:42 +0200 Subject: [PATCH 07/11] wip --- src/Commands/stubs/user-repository.stub | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Commands/stubs/user-repository.stub b/src/Commands/stubs/user-repository.stub index 778073359..9e88ae07a 100644 --- a/src/Commands/stubs/user-repository.stub +++ b/src/Commands/stubs/user-repository.stub @@ -4,6 +4,7 @@ namespace App\Restify; use Binaryk\LaravelRestify\Fields\Field; use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; class UserRepository extends Repository @@ -15,7 +16,7 @@ class UserRepository extends Repository return [ Field::make('name')->rules('required'), - Field::make('email')->storingRules('required', ''unique:users')->messages([ + Field::make('email')->storingRules('required', 'unique:users')->messages([ 'required' => 'This field is required.', ]), From de9658d24922fcb468010dc105d87d95f22f6140 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Wed, 30 Dec 2020 20:09:56 +0200 Subject: [PATCH 08/11] wip --- src/Controllers/AuthController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index dfaf9edbc..064d62414 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -31,11 +31,15 @@ public function verify(Request $request, $id, $hash = null) public function forgotPassword(Request $request) { - return $this->authService->forgotPassword($request); + $this->authService->forgotPassword($request); + + return response(); } public function resetPassword(Request $request) { - return $this->authService->resetPassword($request); + $this->authService->resetPassword($request); + + return response(); } } From f1ea4cc3e339cabcc80ce395f1aded6555f9f6a3 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Wed, 30 Dec 2020 22:22:36 +0200 Subject: [PATCH 09/11] wip --- src/Controllers/AuthController.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 064d62414..dfaf9edbc 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -31,15 +31,11 @@ public function verify(Request $request, $id, $hash = null) public function forgotPassword(Request $request) { - $this->authService->forgotPassword($request); - - return response(); + return $this->authService->forgotPassword($request); } public function resetPassword(Request $request) { - $this->authService->resetPassword($request); - - return response(); + return $this->authService->resetPassword($request); } } From a9882fe97eb9bb667a50c925f55c68e954785dc3 Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Wed, 30 Dec 2020 22:23:04 +0200 Subject: [PATCH 10/11] wip --- src/Eager/Related.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Eager/Related.php b/src/Eager/Related.php index e0b9920d1..7b713b463 100644 --- a/src/Eager/Related.php +++ b/src/Eager/Related.php @@ -5,8 +5,9 @@ use Binaryk\LaravelRestify\Fields\EagerField; use Binaryk\LaravelRestify\Repositories\Repository; use Binaryk\LaravelRestify\Traits\Make; +use JsonSerializable; -class Related implements \JsonSerializable +class Related implements JsonSerializable { use Make; From a5fff25aab0e0e8c6f35f27b7edf6c238e62eccd Mon Sep 17 00:00:00 2001 From: Eduard Lupacescu Date: Wed, 30 Dec 2020 22:25:50 +0200 Subject: [PATCH 11/11] merge --- src/Repositories/Repository.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index dfefb80aa..e39143b15 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -2,6 +2,7 @@ namespace Binaryk\LaravelRestify\Repositories; +use Binaryk\LaravelRestify\Actions\Action; use Binaryk\LaravelRestify\Contracts\RestifySearchable; use Binaryk\LaravelRestify\Controllers\RestResponse; use Binaryk\LaravelRestify\Eager\Related; @@ -1074,4 +1075,18 @@ public function isEagerState(): bool { return $this->eagerState === true; } + + public function restifyjsSerialize(RestifyRequest $request): array + { + return [ + 'uriKey' => static::uriKey(), + 'related' => static::collectFilters('matches'), + 'sort' => static::collectFilters('sortables'), + 'match' => static::collectFilters('matches'), + 'searchables' => static::collectFilters('searchables'), + 'actions' => $this->resolveActions($request)->filter(fn (Action $action) => $action->isShownOnIndex( + $request, $this + ))->values(), + ]; + } }