Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages

Readme

Nova Link Field

composer require upline/nova-link-field
  • Link is displayed as a resource link in the index and detail views.
  • In forms, the link is shown as a text input.

Usage

use Upline\NovaLinkField\Link;


class User extends Resource
{
   // ...
   public function fields(NovaRequest $request) 
   {
        return [
            // ...
            Link::make('Instagram')                 // Get link from instagram model field
                ->text(fn() => 'Instagram link')    // Set static anchor 
                ->target('_blank')                  // Set target attribute
        ];   
   }
}
use Upline\NovaLinkField\Link;


class User extends Resource
{
   // ...
   public function fields(NovaRequest $request) 
   {
        return [
            // ...
            Link::make('Instagram', fn($resource) => 'https://instagram.com/' . $resource->instagramId) // Compute link
                ->text('instagram_username')    // Use instagram_username field as anchor text 
                ->target('_blank')
        ];   
   }
}

Why it is better than

In this example we don't escape $username, so we can get some security troubles.

Text::make('Twitter Profile', function () {
    $username = $this->twitterUsername;

    return "<a href='https://twitter.com/{$username}'>@{$username}</a>";
})->asHtml(),  

Same, using this package:

Link::make('Twitter Profile', function () {
    $username = $this->twitterUsername;
    return "https://twitter.com/{$username}";
})->text('username'),  

However, in this case link and username will be escaped. If you need to use html in anchor text, you still can use asHtml() method.

Back to Top
Added 2 years ago
Last updated 2 Years Ago
Version 1.0.0
Nova Version ^4.0
Composer
upline/nova-link-field
GitHub stars 1
Packagist downloads 19,725

Favorites

0 users favorited

Rating

N/A
(out of 5)
★★★★★
★★★★
★★★
★★
0 ratings

Author

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas