codelinde/laravel-navsmith 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

codelinde/laravel-navsmith

最新稳定版本:0.1.0

Composer 安装命令:

composer require codelinde/laravel-navsmith

包简介

Create navigation links from Laravel routes with ease.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Navsmith is a lightweight, unintrusive Laravel package for easily creating navigation links out of routes you define. It's particularly useful for SPA-like sites.

Usage

Just define your routes using the navsmith method and give them route names you'd like to use in your display...

Route::navsmith(function () {
    Route::get('/', Welcome::class)->name('home');
    Route::get('/about', About::class)->name('about');
    Route::get('/contact', Contact::class)->name('contact');
});

Include the x-navsmith Blade component...

<ul>
    <x-navsmith/>
</ul>

And you get display-ready HTML links.

<ul>
    <li><a href="https://mysite.com">Home</a>
    </li>
    <li><a href="https://mysite.com/about">About</a>
    </li>
    <li><a href="https://mysite.com/contact">Contact</a>
    </li>
</ul>

Using the current attribute on the component, you can give the links different styling according to whether they are the currently-visited page (either CSS styles or class-based styles) and get a SPA-like experience:

Class-based styles (e.g. TailwindCSS)

<!-- This... -->
<x-navsmith class="text-black" current="font-bold"/>

<!-- Will render the link corresponding to the current page, like this... -->
<a href="https://mysite.com" class="text-black font-bold">Home</a>

CSS styles

<!-- This... -->
<x-navsmith style="color: rgb(0 0 0);" current="font-weight: 700;"/>

<!-- Will render the link corresponding to the current page, like this... -->
<a href="https://mysite.com" style="color: rgb(0 0 0); font-weight: 700;">Home</a>

You can also pass through any attributes to your links. This is particularly useful if you're using Livewire and want to take advantage of its SPA-like navigation features by using wire:navigate.

<!-- This... -->
<x-navsmith wire:navigate/>

<!-- Will render each of your links with the same attribute... -->
<a href="https://mysite.com" wire:navigate>Home</a>

Furthermore, a navsmith_route helper function is provided so that you can refer to your Navsmith routes elsewhere in your code without having to remember the specific naming prefix applied.

Given a route definition like this

Route::navsmith(function () {
    Route::get('/a-cumbersome-url', Contact::class)->name('contact');
});

And a call to navsmith_route like this

<p>Please visit the <a href="{{ navsmith_route('contact') }}">contact page</a> to send us an e-mail.</p>

The HTML will render like this

<p>Please visit the <a href="https://mysite.com/a-cumbersome-url">contact page</a> to send us an e-mail.</p>

Requirements

Navsmith requires Laravel 10 or 11 and PHP 8.2+.

Installation

You can install the package via composer:

composer require codelinde/navsmith

Customization

You can publish the views to make any desired alterations by running the following command.

php artisan vendor:publish --tag="navsmith-views"

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-12