diff --git a/app/Models/Model.php b/app/Models/Model.php index 5b34d9f..ae4b483 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 132fd6e..fe1c6ce 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 7baddfb..19d15c5 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') }} + +
@elseif (auth()->user())