ldc-mesbr-app/app/Models/Campaign.php

59 lines
1.2 KiB
PHP
Raw Normal View History

2023-09-13 16:48:17 +02:00
<?php
namespace App\Models;
use App\Enums\CampaignTypes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Campaign extends Model
{
use HasFactory;
2023-09-14 16:00:27 +02:00
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'type',
'status',
'brand_id',
2023-09-14 16:00:27 +02:00
];
2023-09-13 16:48:17 +02:00
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'type' => CampaignTypes::class,
'status' => 'bool',
2023-09-13 16:48:17 +02:00
];
2023-11-24 15:35:08 +01:00
// * RELATIONS
/**
* Get the brand that owns the Campaign
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2023-09-14 16:00:27 +02:00
public function brand(): BelongsTo
{
2023-09-13 16:48:17 +02:00
return $this->belongsTo(Brand::class);
}
2023-11-24 15:35:08 +01:00
/**
* Get coupons that owned by the Campaign
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
2023-09-14 16:00:27 +02:00
public function coupons(): BelongsToMany
2023-09-13 16:48:17 +02:00
{
return $this->belongsToMany(Coupon::class);
}
}