定制 marshmallow/redirectable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

marshmallow/redirectable

Composer 安装命令:

composer require marshmallow/redirectable

包简介

Store redirects via Nova and load them in your routes

README 文档

README

alt text

Laravel Redirectable

Latest Version on Packagist Tests Total Downloads

Store redirects via Nova and load them in your routes.

Redirectable lets you manage HTTP redirects from a Laravel Nova resource and serve them as real, cacheable routes. Redirects can be standalone or attached (polymorphically) to any Eloquent model — for example a page resource — so that when a model's slug changes, its old URLs keep pointing at the right place.

Installation

Install the package via Composer:

composer require marshmallow/redirectable

The service provider is auto-discovered and the package migrations are loaded automatically. Run them with:

php artisan migrate

This creates the redirects table.

Optionally publish the config file:

php artisan vendor:publish --provider="Marshmallow\Redirectable\RedirectableServiceProvider"

Configuration

The published config/redirectable.php exposes the following keys:

Key Default Description
database.connection null Database connection used when checking whether redirect routes should be loaded. null uses the default connection.
models.redirect Marshmallow\Redirectable\Models\Redirect::class The Eloquent model used to store and resolve redirects. Override to use your own model.
types [Marshmallow\Pages\Nova\Page::class] Nova resources that may be associated with a redirect via the MorphTo field.
http_codes [301 => '301 Moved Permanently'] The HTTP status codes selectable in Nova when creating a redirect.

Usage

Register the redirect routes

Call Redirector::routes() in your routes/web.php so the stored redirects are registered as routes. They are added last, never overriding existing application routes, and can be route-cached:

use Marshmallow\Redirectable\Facades\Redirector;

// routes/web.php — register this after your own routes
Redirector::routes();

When a registered redirect URL is hit, the package resolves the final destination (following chained redirects) and returns a redirect response with the configured HTTP code.

Manage redirects in Nova

Register the bundled Nova resource in your NovaServiceProvider:

use Marshmallow\Redirectable\Nova\Redirect;

protected function resources(): void
{
    Nova::resources([
        Redirect::class,
    ]);
}

The resource appears under the SEO group and lets you set the source path (redirect this), the destination (to this), the HTTP code, and an optional associated resource.

Attach redirects to a model

Add the Redirectable trait to any model you want to attach redirects to. It provides a redirectable() morph-many relation:

use Illuminate\Database\Eloquent\Model;
use Marshmallow\Redirectable\Traits\Redirectable;

class Page extends Model
{
    use Redirectable;
}

You can then create redirects for that model through the Redirector facade. add() records a redirect, removes redirects made obsolete by the new destination, and re-points existing trailing redirects to the new destination:

use Marshmallow\Redirectable\Facades\Redirector;

Redirector::add($page, '/old-url', '/new-url');

Testing

composer test

Changelog

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

Contributing

Please see the Marshmallow packages contribution process for details. Pull requests are welcome.

Security Vulnerabilities

If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.

Credits

License

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

统计信息

  • 总下载量: 12.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固