定制 oleaass/laravel-sluggable 二次开发

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

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

oleaass/laravel-sluggable

Composer 安装命令:

composer require oleaass/laravel-sluggable

包简介

Add unique slugs to Eloquent models in Laravel

README 文档

README

This package allows you to automatically create and/or update slugs when saving Eloquent models.

Installation

$ composer require oleaass/laravel-sluggable

Usage

Make your Eloquent model sluggable

namespace App\Models;

use OleAass\Sluggable\Sluggable;

class Post extends Model
{
    use Sluggable;
    
    public function getSlugOptions() : array
    {
        return [
            'source' => 'title'
        ];
    }
}

Example

$post = \App\Models\Post::create([
    'title' => 'My first post'
]);

echo $post->slug; // Output: my-first-post

Options

These are the available options, with default values, which you can override via getSlugOptions() on your Eloquent model.

[
    'source'            => 'title', // The field used as source for the slug
    'dest'              => 'slug',  // Name of the slug column
    'onCreate'          => true,    // If true, automatically create slug when creating a new resource
    'onUpdate'          => false,   // If true, automatically change slug when updating an existing resource
    'allowOverwrite'    => true,    // If true, overwrite existing slug when updating a resource
    'allowDuplicate'    => false,   // If true, non unique slugs can be created (recommended to be false always)
    'delimiter'         => '-',     // Replace spaces with this
];

Support Me

I spend my free time making packages. So if you want to support me and my work, I would really appreciate if you bough me a coffee.

Buy Me A Coffee

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固