12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- class DistAppearancePublishList extends Model
- {
- use HasFactory;
- protected $table = 'dist_appearance_publish_list';
- // 如果主键字段不是 'id',可以指定
- protected $primaryKey = 'id';
- // 反向关联:每个 AppearancePublish 属于一个 Distributor
- public function distributor()
- {
- return $this->belongsTo(DistAdminDistributor::class, 'dist_id', 'id');
- }
- // 新增:与 DistAppearance 的关联
- public function appearance()
- {
- return $this->belongsTo(DistAppearance::class, 'appearance_id', 'id');
- }
- /**
- * 根据 dist_id 和 appearance_id 查找唯一记录
- *
- * @param int $dist_id
- * @param int $appearance_id
- * @return self|null
- */
- public static function findByDistAndAppearance(int $dist_id, int $appearance_id)
- {
- return self::where('dist_id', $dist_id)
- ->where('appearance_id', $appearance_id)
- ->first(); // 返回唯一记录或 null
- }
- }
|