ldc-crm/app/Models/BrandContactList.php
2026-10-08 10:06:20 +02:00

65 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
class BrandContactList extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'brand_id',
'mailjet_list_id',
];
// * METHODS
/**
* Create a brand contact list.
*
* @param Brand $brand
* @param integer $mailjetListId
* @return BrandContactList
*/
public static function createBrandContactList(Brand $brand, int $mailjetListId): BrandContactList
{
$brandContactList = self::create([
'brand_id' => $brand->getKey(),
'mailjet_list_id' => $mailjetListId,
]);
Cache::put("brand_contact_list_{$mailjetListId}", $brandContactList, 86400);
return $brandContactList;
}
/**
* Get brand contact list by mailjet_list_id.
*
* @param integer $mailjetListId
* @return BrandContactList|null
*/
public static function getBrandContactListByMailjetListId(int $mailjetListId): ?BrandContactList
{
return Cache::remember("brand_contact_list_{$mailjetListId}", 86400, function () use ($mailjetListId) {
return self::query()->where('mailjet_list_id', $mailjetListId)->with('brand')->first();
});
}
// * RELATIONS
/**
* Brand belongs to relation.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Brand::class);
}
}