Skip to content

Commit bdc8d41

Browse files
authored
feat: add withoutSearch method to resource registration
2 parents 48040f7 + 1dd160f commit bdc8d41

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Http/Routing/PendingResourceRegistration.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,20 @@ public function withoutBatch(): PendingResourceRegistration
6363

6464
return $this;
6565
}
66+
67+
/**
68+
* Disables the search operation on the resource.
69+
*
70+
* @return $this
71+
*/
72+
public function withoutSearch(): PendingResourceRegistration
73+
{
74+
$except = Arr::get($this->options, 'except');
75+
76+
$except = array_merge($except, ['search']);
77+
78+
$this->except($except);
79+
80+
return $this;
81+
}
6682
}

tests/Unit/OrionTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,4 +689,49 @@ function () {
689689
$this->assertRouteRegistered('api.projects.users.batchDestroy', ['DELETE'], 'api/projects/{project}/users/batch', DummyController::class.'@batchDestroy');
690690
$this->assertRouteRegistered('api.projects.users.batchRestore', ['POST'], 'api/projects/{project}/users/batch/restore', DummyController::class.'@batchRestore');
691691
}
692+
693+
/** @test */
694+
public function registering_resource_without_batch_removes_routes(): void
695+
{
696+
Route::group(
697+
['as' => 'api.', 'prefix' => 'api'],
698+
function () {
699+
Orion::resource('projects', DummyController::class)->withoutBatch();
700+
}
701+
);
702+
703+
$this->assertRouteRegistered('api.projects.search', ['POST'], 'api/projects/search', DummyController::class.'@search');
704+
$this->assertRouteRegistered('api.projects.index', ['GET', 'HEAD'], 'api/projects', DummyController::class.'@index');
705+
$this->assertRouteRegistered('api.projects.store', ['POST'], 'api/projects', DummyController::class.'@store');
706+
$this->assertRouteRegistered('api.projects.show', ['GET', 'HEAD'], 'api/projects/{project}', DummyController::class.'@show');
707+
$this->assertRouteRegistered('api.projects.update', ['PUT', 'PATCH'], 'api/projects/{project}', DummyController::class.'@update');
708+
$this->assertRouteRegistered('api.projects.destroy', ['DELETE'], 'api/projects/{project}', DummyController::class.'@destroy');
709+
710+
$this->assertRouteNotRegistered('api.projects.batchStore');
711+
$this->assertRouteNotRegistered('api.projects.batchUpdate');
712+
$this->assertRouteNotRegistered('api.projects.batchDestroy');
713+
}
714+
715+
/** @test */
716+
public function registering_resource_without_search_removes_routes(): void
717+
{
718+
Route::group(
719+
['as' => 'api.', 'prefix' => 'api'],
720+
function () {
721+
Orion::resource('projects', DummyController::class)->withoutSearch();
722+
}
723+
);
724+
725+
$this->assertRouteNotRegistered('api.projects.search');
726+
727+
$this->assertRouteRegistered('api.projects.index', ['GET', 'HEAD'], 'api/projects', DummyController::class.'@index');
728+
$this->assertRouteRegistered('api.projects.store', ['POST'], 'api/projects', DummyController::class.'@store');
729+
$this->assertRouteRegistered('api.projects.show', ['GET', 'HEAD'], 'api/projects/{project}', DummyController::class.'@show');
730+
$this->assertRouteRegistered('api.projects.update', ['PUT', 'PATCH'], 'api/projects/{project}', DummyController::class.'@update');
731+
$this->assertRouteRegistered('api.projects.destroy', ['DELETE'], 'api/projects/{project}', DummyController::class.'@destroy');
732+
733+
$this->assertRouteRegistered('api.projects.batchStore', ['POST'], 'api/projects/batch', DummyController::class.'@batchStore');
734+
$this->assertRouteRegistered('api.projects.batchUpdate', ['PATCH'], 'api/projects/batch', DummyController::class.'@batchUpdate');
735+
$this->assertRouteRegistered('api.projects.batchDestroy', ['DELETE'], 'api/projects/batch', DummyController::class.'@batchDestroy');
736+
}
692737
}

0 commit comments

Comments
 (0)