diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php
index db7888c1..63023d87 100644
--- a/resources/views/app.blade.php
+++ b/resources/views/app.blade.php
@@ -5,6 +5,7 @@
+
{{-- Styles --}}
diff --git a/routes/web.php b/routes/web.php
index 9c884374..a7a87743 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -3,6 +3,8 @@
use Cone\Root\Http\Controllers\DashboardController;
use Cone\Root\Http\Controllers\DownloadController;
use Cone\Root\Http\Controllers\ResourceController;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route;
// Dashboard
@@ -12,11 +14,14 @@
Route::get('/download/{medium:uuid}', DownloadController::class)->name('download');
// Resource
-Route::get('/{resource}', [ResourceController::class, 'index'])->name('resource.index');
-Route::get('/{resource}/create', [ResourceController::class, 'create'])->name('resource.create');
-Route::post('/{resource}', [ResourceController::class, 'store'])->name('resource.store');
-Route::get('/{resource}/{resourceModel}', [ResourceController::class, 'show'])->name('resource.show');
-Route::get('/{resource}/{resourceModel}/edit', [ResourceController::class, 'edit'])->name('resource.edit');
-Route::patch('/{resource}/{resourceModel}', [ResourceController::class, 'update'])->name('resource.update');
-Route::delete('/{resource}/{resourceModel}', [ResourceController::class, 'destroy'])->name('resource.delete');
-Route::post('/{resource}/{resourceModel}/restore', [ResourceController::class, 'restore'])->name('resource.restore');
+Route::get('/resources', static function (): RedirectResponse {
+ return Redirect::route('root.dashboard');
+});
+Route::get('/resources/{resource}', [ResourceController::class, 'index'])->name('resource.index');
+Route::get('/resources/{resource}/create', [ResourceController::class, 'create'])->name('resource.create');
+Route::post('/resources/{resource}', [ResourceController::class, 'store'])->name('resource.store');
+Route::get('/resources/{resource}/{resourceModel}', [ResourceController::class, 'show'])->name('resource.show');
+Route::get('/resources/{resource}/{resourceModel}/edit', [ResourceController::class, 'edit'])->name('resource.edit');
+Route::patch('/resources/{resource}/{resourceModel}', [ResourceController::class, 'update'])->name('resource.update');
+Route::delete('/resources/{resource}/{resourceModel}', [ResourceController::class, 'destroy'])->name('resource.delete');
+Route::post('/resources/{resource}/{resourceModel}/restore', [ResourceController::class, 'restore'])->name('resource.restore');
diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php
index 4bbf56b2..67f11fa0 100644
--- a/src/Resources/Resource.php
+++ b/src/Resources/Resource.php
@@ -126,6 +126,14 @@ public function getUriKey(): string
return $this->getKey();
}
+ /**
+ * Get the route prefix.
+ */
+ public function getRoutePrefix(): string
+ {
+ return sprintf('resources/%s', $this->getUriKey());
+ }
+
/**
* Get the route parameter name.
*/
@@ -572,7 +580,7 @@ public function registerRoutes(Request $request, Router $router): void
$this->__registerRoutes($request, $router);
$router->group([
- 'prefix' => $this->getUriKey(),
+ 'prefix' => $this->getRoutePrefix(),
'middleware' => $this->getRouteMiddleware(),
], function (Router $router) use ($request): void {
$this->resolveActions($request)->registerRoutes($request, $router);
diff --git a/src/Root.php b/src/Root.php
index 8c0785dd..05553874 100644
--- a/src/Root.php
+++ b/src/Root.php
@@ -12,6 +12,7 @@
use DateTimeZone;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
+use Illuminate\Routing\Router;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Route;
@@ -98,6 +99,10 @@ public static function instance(): static
*/
public function boot(): void
{
+ $this->routes(function (Router $router): void {
+ $this->widgets->registerRoutes($this->app['request'], $router);
+ });
+
$this->resources->discoverIn($this->app->path('Root/Resources'));
$this->resources->each->boot($this);
@@ -108,14 +113,14 @@ public function boot(): void
$this->breadcrumbs->patterns([
$this->getPath() => __('Dashboard'),
- sprintf('%s/{resource}', $this->getPath()) => static function (Request $request): string {
+ sprintf('%s/resources/{resource}', $this->getPath()) => static function (Request $request): string {
return $request->route('_resource')->getName();
},
- sprintf('%s/{resource}/create', $this->getPath()) => __('Create'),
- sprintf('%s/{resource}/{resourceModel}', $this->getPath()) => static function (Request $request): string {
+ sprintf('%s/resources/{resource}/create', $this->getPath()) => __('Create'),
+ sprintf('%s/resources/{resource}/{resourceModel}', $this->getPath()) => static function (Request $request): string {
return $request->route('_resource')->modelTitle($request->route('resourceModel'));
},
- sprintf('%s/{resource}/{resourceModel}/edit', $this->getPath()) => __('Edit'),
+ sprintf('%s/resources/{resource}/{resourceModel}/edit', $this->getPath()) => __('Edit'),
]);
}
diff --git a/src/Traits/RegistersRoutes.php b/src/Traits/RegistersRoutes.php
index 4df9089c..09a9e95a 100644
--- a/src/Traits/RegistersRoutes.php
+++ b/src/Traits/RegistersRoutes.php
@@ -29,6 +29,14 @@ public function getUri(): ?string
return $this->uri;
}
+ /**
+ * Get the route prefix.
+ */
+ public function getRoutePrefix(): string
+ {
+ return (string) $this->getUriKey();
+ }
+
/**
* Get the route parameter name.
*/
@@ -50,11 +58,11 @@ public function getRouteMiddleware(): array
*/
public function registerRoutes(Request $request, Router $router): void
{
- $this->uri = Str::start(sprintf('%s/%s', $router->getLastGroupPrefix(), $this->getUriKey()), '/');
+ $this->uri = Str::start(sprintf('%s/%s', $router->getLastGroupPrefix(), $this->getRoutePrefix()), '/');
if (! App::routesAreCached()) {
$router->group([
- 'prefix' => $this->getUriKey(),
+ 'prefix' => $this->getRoutePrefix(),
'middleware' => $this->getRouteMiddleware(),
], function (Router $router): void {
$this->routes($router);
diff --git a/tests/Http/ActionControllerTest.php b/tests/Http/ActionControllerTest.php
index 79b128a1..d4cf167f 100644
--- a/tests/Http/ActionControllerTest.php
+++ b/tests/Http/ActionControllerTest.php
@@ -19,7 +19,7 @@ protected function setUp(): void
public function test_action_controller_handles_action_request(): void
{
$this->actingAs($this->admin)
- ->post('/root/users/actions/send-password-reset-notification')
+ ->post('/root/resources/users/actions/send-password-reset-notification')
->assertRedirect()
->assertSessionHas('alerts.action-send-password-reset-notification');
}
diff --git a/tests/Http/BelongsToManyControllerTest.php b/tests/Http/BelongsToManyControllerTest.php
index 335907af..9bb7d72b 100644
--- a/tests/Http/BelongsToManyControllerTest.php
+++ b/tests/Http/BelongsToManyControllerTest.php
@@ -40,7 +40,7 @@ protected function setUp(): void
public function test_belongs_to_many_controller_handles_index(): void
{
$this->actingAs($this->admin)
- ->get('/root/users/'.$this->admin->getKey().'/fields/teams')
+ ->get('/root/resources/users/'.$this->admin->getKey().'/fields/teams')
->assertOk()
->assertViewIs('root::resources.index')
->assertViewHas($this->field->toIndex($this->app['request'], $this->admin));
@@ -51,7 +51,7 @@ public function test_belongs_to_many_controller_handles_store(): void
$team = Team::factory()->create();
$this->actingAs($this->admin)
- ->post('/root/users/'.$this->admin->getKey().'/fields/teams', [
+ ->post('/root/resources/users/'.$this->admin->getKey().'/fields/teams', [
'related' => $team->getKey(),
'role' => 'member',
])
@@ -72,7 +72,7 @@ public function test_belongs_to_many_controller_handles_update(): void
$this->assertSame('admin', $team->pivot->role);
$this->actingAs($this->admin)
- ->patch('/root/users/'.$this->admin->getKey().'/fields/teams/'.$team->pivot->getKey(), [
+ ->patch('/root/resources/users/'.$this->admin->getKey().'/fields/teams/'.$team->pivot->getKey(), [
'related' => $team->getKey(),
'role' => 'member',
])
@@ -87,7 +87,7 @@ public function test_belongs_to_many_controller_handles_destroy(): void
$team = $this->admin->teams->first();
$this->actingAs($this->admin)
- ->delete('/root/users/'.$this->admin->getKey().'/fields/teams/'.$team->pivot->getKey())
+ ->delete('/root/resources/users/'.$this->admin->getKey().'/fields/teams/'.$team->pivot->getKey())
->assertRedirect()
->assertSessionHas('alerts.relation-deleted');
diff --git a/tests/Http/MediaControllerTest.php b/tests/Http/MediaControllerTest.php
index 2cd45356..96d0cd7d 100644
--- a/tests/Http/MediaControllerTest.php
+++ b/tests/Http/MediaControllerTest.php
@@ -36,7 +36,7 @@ protected function setUp(): void
public function test_media_controller_handles_index(): void
{
$this->actingAs($this->admin)
- ->get('/root/users/'.$this->admin->getKey().'/fields/media')
+ ->get('/root/resources/users/'.$this->admin->getKey().'/fields/media')
->assertOk()
->assertJson($this->field->paginateRelatable($this->app['request'], $this->admin)->toArray());
}
@@ -47,7 +47,7 @@ public function test_media_controller_handles_store(): void
$this->actingAs($this->admin)
->post(
- '/root/users/'.$this->admin->getKey().'/fields/media',
+ '/root/resources/users/'.$this->admin->getKey().'/fields/media',
['file' => UploadedFile::fake()->image('test.png')],
['X-Chunk-Index' => 1, 'X-Chunk-Total' => 1]
)
@@ -64,7 +64,7 @@ public function test_media_controller_handles_destroy(): void
$medium = Medium::factory()->create();
$this->actingAs($this->admin)
- ->delete('/root/users/'.$this->admin->getKey().'/fields/media', ['ids' => [$medium->getKey()]])
+ ->delete('/root/resources/users/'.$this->admin->getKey().'/fields/media', ['ids' => [$medium->getKey()]])
->assertOk()
->assertJson(['deleted' => [1]]);
diff --git a/tests/Http/MorphToControllerTest.php b/tests/Http/MorphToControllerTest.php
index f6695345..11a2d8d7 100644
--- a/tests/Http/MorphToControllerTest.php
+++ b/tests/Http/MorphToControllerTest.php
@@ -31,7 +31,7 @@ protected function setUp(): void
public function test_morph_to_controller_handles_request(): void
{
$this->actingAs($this->admin)
- ->get('/root/users/'.$this->admin->getKey().'/fields/employer')
+ ->get('/root/resources/users/'.$this->admin->getKey().'/fields/employer')
->assertOk()
->assertViewIs('root::fields.morph-to')
->assertViewHas($this->field->toInput($this->app['request'], $this->admin));
diff --git a/tests/Http/RelationControllerTest.php b/tests/Http/RelationControllerTest.php
index 7ca57327..923eff0d 100644
--- a/tests/Http/RelationControllerTest.php
+++ b/tests/Http/RelationControllerTest.php
@@ -38,7 +38,7 @@ protected function setUp(): void
public function test_relation_controller_handles_index(): void
{
$this->actingAs($this->admin)
- ->get('/root/users/'.$this->admin->getKey().'/fields/uploads')
+ ->get('/root/resources/users/'.$this->admin->getKey().'/fields/uploads')
->assertOk()
->assertViewIs('root::resources.index')
->assertViewHas($this->field->toIndex($this->app['request'], $this->admin));
@@ -47,7 +47,7 @@ public function test_relation_controller_handles_index(): void
public function test_relation_controller_handles_create(): void
{
$this->actingAs($this->admin)
- ->get('/root/users/'.$this->admin->getKey().'/fields/uploads/create')
+ ->get('/root/resources/users/'.$this->admin->getKey().'/fields/uploads/create')
->assertOk()
->assertViewIs('root::resources.form')
->assertViewHas($this->field->toCreate($this->app['request'], $this->admin));
@@ -56,7 +56,7 @@ public function test_relation_controller_handles_create(): void
public function test_relation_controller_handles_store(): void
{
$this->actingAs($this->admin)
- ->post('/root/users/'.$this->admin->getKey().'/fields/uploads', $data = Medium::factory()->make()->toArray())
+ ->post('/root/resources/users/'.$this->admin->getKey().'/fields/uploads', $data = Medium::factory()->make()->toArray())
->assertRedirect()
->assertSessionHas('alerts.relation-created');
@@ -72,7 +72,7 @@ public function test_relation_controller_handles_show(): void
});
$this->actingAs($this->admin)
- ->get('/root/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey())
+ ->get('/root/resources/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey())
->assertOk()
->assertViewIs('root::resources.show')
->assertViewHas($this->field->toShow($this->app['request'], $this->admin, $this->medium));
@@ -85,7 +85,7 @@ public function test_relation_controller_handles_edit(): void
});
$this->actingAs($this->admin)
- ->get('/root/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey().'/edit')
+ ->get('/root/resources/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey().'/edit')
->assertOk()
->assertViewIs('root::resources.form')
->assertViewHas($this->field->toEdit($this->app['request'], $this->admin, $this->medium));
@@ -99,7 +99,7 @@ public function test_relation_controller_handles_update(): void
$this->actingAs($this->admin)
->patch(
- '/root/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey(),
+ '/root/resources/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey(),
array_merge($this->medium->toArray(), ['file_name' => 'updated.png'])
)
->assertRedirect()
@@ -115,7 +115,7 @@ public function test_relation_controller_handles_destroy(): void
});
$this->actingAs($this->admin)
- ->delete('/root/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey())
+ ->delete('/root/resources/users/'.$this->admin->getKey().'/fields/uploads/'.$this->medium->getKey())
->assertRedirect()
->assertSessionHas('alerts.relation-deleted');
diff --git a/tests/Http/RepeaterControllerTest.php b/tests/Http/RepeaterControllerTest.php
index dce5d5e3..c5701e48 100644
--- a/tests/Http/RepeaterControllerTest.php
+++ b/tests/Http/RepeaterControllerTest.php
@@ -31,7 +31,7 @@ protected function setUp(): void
public function test_repeater_controller_handles_request(): void
{
$this->actingAs($this->admin)
- ->post('/root/users/'.$this->admin->getKey().'/fields/settings')
+ ->post('/root/resources/users/'.$this->admin->getKey().'/fields/settings')
->assertOk();
}
}
diff --git a/tests/Http/WidgetControllerTest.php b/tests/Http/WidgetControllerTest.php
index b7e55ac6..a7976767 100644
--- a/tests/Http/WidgetControllerTest.php
+++ b/tests/Http/WidgetControllerTest.php
@@ -31,7 +31,7 @@ protected function setUp(): void
public function test_widget_controller_handles_request(): void
{
$this->actingAs($this->admin)
- ->get('/root/users/widgets/users-count')
+ ->get('/root/resources/users/widgets/users-count')
->assertOk()
->assertViewIs($this->widget->getTemplate())
->assertViewHas($this->widget->data($this->app['request']));
diff --git a/tests/Resources/ResourceTest.php b/tests/Resources/ResourceTest.php
index 32e0d150..959987b5 100644
--- a/tests/Resources/ResourceTest.php
+++ b/tests/Resources/ResourceTest.php
@@ -105,7 +105,7 @@ public function test_a_resource_registers_routes(): void
{
$action = $this->resource->resolveActions($this->app['request'])->first();
- $this->assertSame('/root/users/actions/send-password-reset-notification', $action->getUri());
+ $this->assertSame('/root/resources/users/actions/send-password-reset-notification', $action->getUri());
$this->assertArrayHasKey(
trim($action->getUri(), '/'),