Laravel Cviebrock / eloquent-sluggable如何生成带有名称和记录ID的

时间:2018-06-26 06:23:08

标签: php laravel package slug

我已经使用了这种“ cviebrock /雄辩的可拖拉” laravel软件包,我需要生成这样的产品塞子

名称:红色衬衫

插入:红色衬衫520(520是红色衬衫产品的记录ID)

以下是用于生成弹头但无法正常工作的模型函数

public function sluggable()
{
    return [
        'slug' => [
            'source' => ['name', 'tbl_products.id'],
            'separator' => '-',
            'onUpdate' => true,
        ]
    ];
}

1 个答案:

答案 0 :(得分:0)

在模型文件中添加如下所示的代码,并将插件详细信息添加到config / app.php provider数组中 Cviebrock \ EloquentSluggable \ ServiceProvider :: class,

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
    {
     use Sluggable;
     public function sluggable() {
        return ['slug'=>[
            'source'=>'full_name',
            'onUpdate'=>true
        ]];
     }
    }