标签关系

This commit is contained in:
2025-03-27 11:13:46 +08:00
parent 6e79dd47c4
commit aff152e40d
7 changed files with 90 additions and 5 deletions
+9
View File
@@ -96,4 +96,13 @@ class Customer extends Model
return $customer;
}
/**
* 客户的标签
*/
public function tags()
{
return $this->belongsToMany(Tag::class, 'customer_tag', 'customer_id', 'tag_id')
->withTimestamps(); // 如果需要记录关联时间
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace app\model;
use app\util\Util;
use support\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class CustomerTag extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'customer_tag';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
//设置黑名单
protected $guarded = ['id', 'created_at'];
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}
+4
View File
@@ -48,4 +48,8 @@ class Tag extends Model
return $this->belongsTo(TagGroup::class, 'group_id', 'id');
}
public function customers()
{
return $this->belongsToMany(Customer::class, 'customer_tag', 'tag_id', 'customer_id');
}
}