定制 zymawy/arabify 二次开发

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

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

zymawy/arabify

最新稳定版本:v1.3.2

Composer 安装命令:

composer require zymawy/arabify

包简介

:closed_lock_with_key: A Wrapper Sluggable Traits, To Deal With Arabic Langauge

README 文档

README

| This Is Just A Wrapper Package To Support Arabic Languages Slug

Provides a HasSlug trait that will generate a unique slug when saving your Laravel Eloquent model.

$model = new Article();
$model->name = 'كيف اتعلم البرمجة';
$model->save();

echo $model->slug; // ouputs "كيف-اتعلم-البرمجة"

Installation

Update your project's composer.json file.

composer require zymawy/arabify

You may want to change the function you can do change it from the config

php artisan vendor:publish --provider="Zymawy\Arabify\ArabifyServiceProvider"

Usage

Your Eloquent models can use the Zymawy\Arabfiy\HasSlug trait and the Zymawy\Arabfiy\SlugOptions class.

The trait has a protected method getSlugOptions() that you can implement for customization.

Here's an example:

class YourEloquentModel extends Model
{
    use HasSlug;
    
    /**
     * This function is optional and only required
     * when you want to override the default behaviour
     */
    protected function getSlugOptions()
    {
        return SlugOptions::create()
            ->slugSeperator('-')
            ->generateSlugFrom('name')
            ->saveSlugTo('slug');
    }
}

If you want to generate your slug from a relationship.

class YourEloquentModel extends Model
{
    use HasSlug;
    
    public function getNameAndFooAttribute()
    {
        $name = $this->name;
        if ($this->foo) {
            $name .= " {$this->foo->name}";
        }

        return $name;
    }
    
    protected function getSlugOptions()
    {
        return SlugOptions::create()
            ->generateSlugFrom('name_and_foo');
    }
}

Config

You do not have to add the method in you model (the above will be used as default). It is only needed when you want to change the default behaviour.

By default it will generate a slug from the name and save to the slug column.

It will suffix a -1 to make the slug unique. You can disable it by calling makeSlugUnique(false).

It will use the - as a separator. You can change this by calling slugSeperator('_').

You can use multiple fields as the source of the slug generateSlugFrom(['firstname', 'lastname']).

You can also pass a callable function to generateSlugFrom().

Have a look here for the options and available config functions.

Credits

See also the list of contributors who participated in this project.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-13