Package Data | |
---|---|
Maintainer Username: | inspheric |
Package Create Date: | 2018-08-27 |
Package Last Update: | 2022-11-28 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:19:03 |
Package Statistics | |
---|---|
Total Downloads: | 1,046,026 |
Monthly Downloads: | 12,616 |
Daily Downloads: | 555 |
Total Stars: | 105 |
Total Watchers: | 2 |
Total Forks: | 17 |
Total Open Issues: | 1 |
A URL input and link field for Laravel Nova
Install the package into a Laravel app that uses Nova with Composer:
composer require inspheric/nova-url-field
Add the field to your resource in the fields
method:
use Inspheric\Fields\Url;
Url::make('Homepage')
->rules('url', /* ... */),
The field extends the Laravel\Nova\Fields\Text
field, so all the usual methods are available.
Now supports readonly, placeholder and overriding the default type="url"
if you prefer not to have the validation in the browser. This is from the standard Nova Text
field so is not documented here.
It is recommended that you include the standard url
and/or active_url
validation rules, as they are not automatically added.
Make the field display with a label instead of the URL value itself on the detail or index pages:
Url::make('Homepage')
->label('External Link'),
You can, of course use the Laravel trans()
or __()
functions to translate the label.
The label is only displayed if the link is clickable, otherwise the URL value is displayed.
Make the field display with a label using a callback:
Url::make('Homepage')
->labelUsing(function($value, $resource) {
return $this->title;
}),
The arguments $value
and $resource
are passed in the same way as the callback for resolveUsing()
, but are optional.
A shortcut method to display the domain part only of the URL (i.e. without https?://www.
) as the label:
Url::make('Homepage')
->domainLabel(),
For example, the label for the field value https://www.example.com/path?query=value&another=true#fragment
would display simply as example.com
.
This is resolved after the displayUsing()
callback if you have one, so if you modify the display of the URL in some way, the modified value will be passed to this label.
A shortcut method to display the name of the field as the label:
Url::make('Homepage')
->nameLabel(),
The label would be displayed as Homepage
.
Make the field display as a link on the detail page:
Url::make('Homepage')
->clickable(),
Make the field display as a link on the index page:
Url::make('Homepage')
->clickableOnIndex(),
Combination of the two functions above for simplicity:
Url::make('Homepage')
->alwaysClickable(),
The field is displayed as a plain <span>
element.
The field is displayed as an <a href="...">
element with an icon.
The field is displayed as an <a href="...">
element with an icon and a custom label.
The field is displayed as a plain <span>
element.
The field is displayed as an <a href="...">
element with an icon.
The field is displayed as an <a href="...">
element with an icon and a custom label.
The field is displayed as an <input type="url">
element.