From 2086888e23f822eebdd19250c1bd2a458ffa0389 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Sat, 17 Jan 2026 18:49:46 -0500 Subject: [PATCH] Add front and backend view links --- app/Models/Model.php | 14 +++++++++++++- app/Nova/Item.php | 7 ++++++- resources/views/items/show.blade.php | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/Models/Model.php b/app/Models/Model.php index 5b34d9f0..ae4b4832 100644 --- a/app/Models/Model.php +++ b/app/Models/Model.php @@ -66,7 +66,7 @@ abstract class Model extends Eloquent * * @var array */ - protected $appends = ['url', 'edit_url']; + protected $appends = ['url', 'edit_url', 'view_url']; /** * The number of items to show per page. @@ -109,6 +109,18 @@ public function getEditUrlAttribute() return '/library/resources/'.$class.'/'.$this->id.'/edit'; } + /** + * Helper attribute for getting the URL to any model. + * + * @return string + */ + public function getViewUrlAttribute() + { + $class = Str::plural(Str::lower(class_basename($this))); + + return '/library/resources/'.$class.'/'.$this->id; + } + /** * Default to the model name, lowercase and plural. * diff --git a/app/Nova/Item.php b/app/Nova/Item.php index 132fd6e5..fe1c6ce9 100644 --- a/app/Nova/Item.php +++ b/app/Nova/Item.php @@ -75,7 +75,12 @@ public function fields(Request $request) { return [ Text::make('ID')->onlyOnDetail(), - Text::make('Slug')->onlyOnDetail(), + Text::make('Slug', function () { + $slug = $this->slug; + $url = $this->url; + + return "{$slug}"; + })->asHtml()->onlyOnDetail(), Avatar::make('Image') ->disk('s3public') diff --git a/resources/views/items/show.blade.php b/resources/views/items/show.blade.php index 7baddfb7..19d15c57 100644 --- a/resources/views/items/show.blade.php +++ b/resources/views/items/show.blade.php @@ -30,6 +30,12 @@ class="rounded mw-100 d-block mx-auto"> {{ __('ui.item.edit') }} + +
+ + {{ __('ui.item.view') }} + +
@elseif (auth()->user())