承接 inspheric/nova-url-field 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

inspheric/nova-url-field

Composer 安装命令:

composer require inspheric/nova-url-field

包简介

A Laravel Nova URL field.

README 文档

README

A better URL input and link field for Laravel Nova. Version 2.0 now supports Nova 4.0 and Vue 3.0!

Latest Version on Packagist Total Downloads

Installation

Install the package into a Laravel app that uses Nova with Composer:

composer require inspheric/nova-url-field

Usage

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.

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.

Options

Terminology: label, title, value

The terms "label", "title" and "value" are used to describe the following options. They should be understood within the generated HTML as follows:

<a href="{{ $value }}" title="{{ $title }}">{{ $label }}</a>

Label

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.

Label Using

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.

HTML Label

If you would like to use custom HTML for the label, remember to also use the asHtml() option.

Url::make('Homepage')
    ->label('<strong>External</strong> Link')
    ->asHtml(),

Domain Label

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.

Name 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.

Title

Set the link's title attribute, which will be displayed when the mouse hovers over it:

Url::make('Homepage')
    ->title('Link title'),

You can, of course use the Laravel trans() or __() functions to translate the label. If no custom title is set, the full URL value will be used.

The title is only used if the link is clickable.

Title Using

Set the title using a callback:

Url::make('Homepage')
    ->titleUsing(function($value, $resource) {
        return $this->title;
    }),

Clickable

Make the field display as a link on the detail page:

Url::make('Homepage')
    ->clickable(bool $clickable = true),

Clickable on Index

Make the field display as a link on the index page:

Url::make('Homepage')
    ->clickableOnIndex(bool $clickable = true),

Always Clickable

Combination of the two functions above for simplicity:

Url::make('Homepage')
    ->alwaysClickable(bool $clickable = true),

Open in Same Tab

By default, the clickable link will open in a new tab (using target="_blank"). You can modify this behaviour so that the link opens in the same tab:

Url::make('Homepage')
    ->sameTab(bool $sameTab = true),

rel=noopener and rel=noreferrer

By default, a clickable link will open in a new tab and will have the rel=noopener attribute set*. If you use sameTab() as above, rel=noopener will be unset.

To override the default behaviour, you can choose to set or unset rel=noopener and/or rel=noreferrer with the following methods:

Url::make('Homepage')
    ->noopener(bool $noopener = true),

Url::make('Homepage')
    ->noreferrer(bool $noreferrer = true),

If you use both sameTab() and noopener() on the same field, ensure that noopener() comes after sameTab() or the two settings will cancel each other out.

* See this article for an explanation.

Custom HTML

If you do not wish the link to be displayed with the default icon and text, you can set custom HTML which will replace the entire contents of the default template:

Url::make('Homepage')
    ->customHtml('<span class="my-class">Click here!</span>'),

If the link is clickable, this content will be wrapped in an unstyled <a> tag which implements all of the other options you have specified, such as sameTab, title etc.

If you do want the link to appear as link-styled text, you can add the classes dim text-primary within the HTML you specify.

Important! It is your responsibility to escape or sanitize any user-provided data before displaying it as raw HTML. This package does not do that for you.

Custom HTML Using

Set the custom HTML using a callback:

Url::make('Homepage')
    ->customHtmlUsing(function($value, $resource, $label) {
        return view('partials.link_text', [
            'url'   => $value,
            'label' => $label,
        ])->render();
    }),

Note that the callback has a third argument $label, which will contain the appropriate label based on which of the label(), labelUsing(), nameLabel(), domainLabel() etc. options you have set on the field.

Remember that if the link is clickable, the custom HTML you specify is already wrapped in an <a href=""> tag, so you should not include an <a> tag in your own custom HTML.

Appearance

Index (default)

index-field

The field is displayed as a plain <span> element.

Index (clickable)

index-field-clickable

The field is displayed as an <a href="..."> element with an icon.

Index (clickable with label)

index-field-clickable-label

The field is displayed as an <a href="..."> element with an icon and a custom label.

Detail (default)

detail-field

The field is displayed as a plain <span> element.

Detail (clickable)

detail-field-clickable

The field is displayed as an <a href="..."> element with an icon.

Detail (clickable with label)

detail-field-clickable-label

The field is displayed as an <a href="..."> element with an icon and a custom label.

Form

form-field

The field is displayed as an <input type="url"> element.

inspheric/nova-url-field 适用场景与选型建议

inspheric/nova-url-field 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.3M 次下载、GitHub Stars 达 102, 最近一次更新时间为 2018 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「url」 「nova」 「laravel」 「field」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 inspheric/nova-url-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 inspheric/nova-url-field 我们能提供哪些服务?
定制开发 / 二次开发

基于 inspheric/nova-url-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.3M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 103
  • 点击次数: 9
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 102
  • Watchers: 1
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-27