👁 查看:Tag.php
路径:/home/boguraj1/.trash/app/Models/Tag.php
大小:515 B · 修改:2026-07-23 16:13:46 · 权限:0644 · 可写
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class Tag extends Model
{
    protected $fillable = ['name', 'slug'];

    protected static function boot()
    {
        parent::boot();
        static::creating(function ($tag) {
            if (empty($tag->slug)) {
                $tag->slug = Str::slug($tag->name);
            }
        });
    }

    public function products()
    {
        return $this->belongsToMany(Product::class, 'product_tag');
    }
}