Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
7 changes: 6 additions & 1 deletion app/Nova/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<a href='{$url}'>{$slug}</a>";
})->asHtml()->onlyOnDetail(),

Avatar::make('Image')
->disk('s3public')
Expand Down
6 changes: 6 additions & 0 deletions resources/views/items/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class="rounded mw-100 d-block mx-auto">
<i class="fal fa-fw fa-edit"></i> {{ __('ui.item.edit') }}
</a>
</div>

<div class="col p-1 list-group text-center small">
<a class="btn btn-outline-primary" href="{{ $item->view_url }}">
<i class="fal fa-fw fa-eye"></i> {{ __('ui.item.view') }}
</a>
</div>
</div>
@elseif (auth()->user())
<div class="row p-0 mx-0 my-3">
Expand Down
Loading