承接 ruthgeridema/laravel-url-rewrites 相关项目开发

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

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

ruthgeridema/laravel-url-rewrites

Composer 安装命令:

composer require ruthgeridema/laravel-url-rewrites

包简介

Easy URL rewrites in your Laravel application

README 文档

README

Latest Version on Packagist Software License Build Status Quality Score StyleCI Total Downloads

Very easy to use URL rewrite package. Follow the instructions and you're good to go!

You can find an example project on my Github: view example project
This example project features the following:

  • Eloquent observers to add URL rewrites automatically
  • Usage of the trait
  • Some use cases

Requirements

This package requires Laravel 5.8 or higher, PHP 7.2 or higher and a database that supports json fields and functions such as MySQL 5.7 or higher.

Installation

You can install the package via composer:

composer require ruthgeridema/laravel-url-rewrites

The package will automatically register itself.

Register the routes the feeds will be displayed on using the rewrites-macro.
You need to place it at the bottom of your routes file.

// In routes/web.php
Route::rewrites();

You can publish the migration with:

php artisan vendor:publish --provider="RuthgerIdema\UrlRewrite\ServiceProvider" --tag="migrations"

After the migration has been published you can create the url_rewrites table by running the migration:

php artisan migrate

You can optionally publish the config file with:

php artisan vendor:publish --provider="RuthgerIdema\UrlRewrite\ServiceProvider" --tag="config"

This is the contents of the published config file:

<?php

return [
    'table-name' => 'url_rewrites',
    'repository' => \RuthgerIdema\UrlRewrite\Repositories\UrlRewriteRepository::class,
    'model' => \RuthgerIdema\UrlRewrite\Entities\UrlRewrite::class,
    'cache' => true,
    'cache-decorator' => \RuthgerIdema\UrlRewrite\Repositories\Decorators\CachingUrlRewriteRepository::class,
    'types' => [
        'product' => [
            'route' => 'product',
            'attributes' => ['id'],
        ],
        'category' => [
            'route' => 'category',
            'attributes' => ['id'],
        ]
    ],
];

Laravel Nova

Using Laravel Nova? You can publish the Nova class to App/Nova with the following command

php artisan vendor:publish --provider="RuthgerIdema\UrlRewrite\ServiceProvider" --tag="nova"

In the near future I will publish a Laravel Nova package with features like reindexing the URL rewrites.

Usage

Forward request

Let's say you've got a controller route 'product/{id}' and you have a product 'Apple Airpods' with id=5.
When you visit 'apple-airpods' this package will forward the request to the controller but keeps the clean url.

The following code adds this to the database:

UrlRewrite::create('apple-airpods', 'product/5')

Use named routes

You must specify the types in the config.

UrlRewrite::create('apple-airpods', null, 'product', ["id" => 5])

To regenerate the target path you can use

UrlRewrite::regenerateRoute($urlRewrite)
UrlRewrite::regenerateAll()
UrlRewrite::regenerateRoutesFromType($type)

To automatically add the URL attribute to an Eloquent model, you have to add the HasUrlRewrite trait to an Eloquent model.
You also need to add the urlRewriteType and optionally add 'url' to the appends array.

use HasUrlRewrite;
public $urlRewriteType = 'category';
protected $appends = ['url'];

Once this is done you can simply call Model::find(1)->url to get the url of the model.

Redirect

301 redirect

UrlRewrite::create('apple-airpods', 'product/5', null, null, 1)

302 redirect

UrlRewrite::create('apple-airpods', 'product/5', null, null, 2)

Other functions

UrlRewrite::all()
UrlRewrite::find($id)
UrlRewrite::delete($id)
UrlRewrite::update($data, $id)
UrlRewrite::getByRequestPath('apple-airpods')
UrlRewrite::getByTargetPath('product/5')
UrlRewrite::getByTypeAndAttributes('product', ["id" => 5])

Testing

  1. Copy .env.example to .env and fill in your database credentials.
  2. Run composer test.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ruthger.idema@gmail.com instead of using the issue tracker.

Credits

Special thanks for Spatie for their guidelines and their packages as an inspiration

License

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

ruthgeridema/laravel-url-rewrites 适用场景与选型建议

ruthgeridema/laravel-url-rewrites 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.02k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2019 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ruthgeridema/laravel-url-rewrites 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 29
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-07