laraeast/laravel-sluggable 问题修复 & 功能扩展

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

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

laraeast/laravel-sluggable

Composer 安装命令:

composer require laraeast/laravel-sluggable

包简介

Easy creation of slugs for your Eloquent models in Laravel

README 文档

README

StyleCI Travis Build Status Circleci Build Status Total Downloads Latest Stable Version License

Easy creation of slugs for your Eloquent models in Laravel.

Background: What is a slug?

A slug is a simplified version of a string, typically URL-friendly. The act of "slugging" a string usually involves converting it to one case, and removing any non-URL-friendly characters (spaces, accented letters, ampersands, etc.). The resulting string can then be used as an identifier for a particular resource.

For example, if you have a blog with posts, you could refer to each post via the ID:

http://example.com/post/1
http://example.com/post/2

... but that's not particularly friendly (especially for SEO). You probably would prefer to use the post's title in the URL, if your post is titled "My Dinner With Ahmed & Omar", the URL will be:

http://example.com/post/1-my-dinner-with-ahmed-omar

Installation

  • Install the package via Composer:

    • For Laravel 5.2 >= 6.x
      $ composer require laraeast/laravel-sluggable:^1.0
    • For Laravel 7.x
      $ composer require laraeast/laravel-sluggable:^2.0

    The package will automatically register its service provider.

Middleware

You should add SluggableRedirectMiddleware to web middileware to redirect to latest updated slug. app/Http/Kernel.php file :

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            ...
            \Laraeast\LaravelSluggable\SluggableRedirectMiddleware::class,
        ],
        ...
    ];

Updating your Eloquent Models

Your models should use the Sluggable trait, which has an abstract method sluggableFields() that you need to define. This is where any model-specific configuration is set

use Laraeast\LaravelSluggable\Sluggable;

class Post extends Model
{
    use Sluggable;

    /**
     * The sluggable fields for model.
     *
     * @return array
     */
    public function sluggableFields()
    {
        return ['name'];
    }
}

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固