+ @can('view', $row['model'])
+
+
+
+ @endcan
@can('update', $row['model'])
-
+
@endcan
diff --git a/routes/web.php b/routes/web.php
index c0c5a8a6..17dd7d97 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -11,7 +11,8 @@
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, 'edit'])->name('resource.edit');
+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');
diff --git a/src/Http/Controllers/ResourceController.php b/src/Http/Controllers/ResourceController.php
index cd7e460e..c66097e2 100644
--- a/src/Http/Controllers/ResourceController.php
+++ b/src/Http/Controllers/ResourceController.php
@@ -70,6 +70,21 @@ public function store(Request $request, Resource $resource): RedirectResponse
->with('alerts.resource-created', Alert::success(__('The resource has been created!')));
}
+ /**
+ * Display the specified resource.
+ */
+ public function show(Request $request, Resource $resource, Model $model): Response
+ {
+ if ($resource->getPolicy()) {
+ $this->authorize('view', $model);
+ }
+
+ return ResponseFactory::view(
+ 'root::resources.show',
+ $resource->toShow($request, $model)
+ );
+ }
+
/**
* Show the form for editing the specified resource.
*/
diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php
index af7229d5..6c051498 100644
--- a/src/Resources/Resource.php
+++ b/src/Resources/Resource.php
@@ -371,6 +371,23 @@ public function toCreate(Request $request): array
]);
}
+ /**
+ * Get the edit representation of the resource.
+ */
+ public function toShow(Request $request, Model $model): array
+ {
+ return array_merge($this->toArray(), [
+ 'title' => sprintf('%s #%s', $this->getModelName(), $model->getKey()),
+ 'model' => $model,
+ 'action' => $this->modelUrl($model),
+ 'method' => 'PATCH',
+ 'fields' => $this->resolveFields($request)
+ ->authorized($request, $model)
+ ->visible('show')
+ ->mapToDisplay($request, $model),
+ ]);
+ }
+
/**
* Get the edit representation of the resource.
*/