128 lines
2.4 KiB
PHP
128 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\CampaignTypes;
|
|
use App\Models\Basket;
|
|
use App\Models\PrintedCoupons;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
|
|
|
class Campagne extends Model
|
|
{
|
|
use SoftDeletes;
|
|
use CastsEnums;
|
|
use HasFactory;
|
|
|
|
public $enumCasts = [
|
|
'camp_type' => CampaignTypes::class
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'camp_siteId',
|
|
'camp_name',
|
|
'camp_type',
|
|
'camp_limitedPrinting',
|
|
'camp_published'
|
|
];
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
const CREATED_AT = 'camp_createdate';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
const UPDATED_AT = 'camp_updatedate';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
const DELETED_AT = 'camp_deleted_at';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $table = 'campagne';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'camp_id';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $dates = ['camp_deleted_at'];
|
|
|
|
|
|
|
|
/**
|
|
* OneToMany
|
|
* Campagne -> Notification
|
|
*/
|
|
public function notifications()
|
|
{
|
|
return $this->hasMany('App\Models\Notification', 'notif_campId', 'camp_id');
|
|
}
|
|
|
|
/**
|
|
* OneToMany
|
|
* Campagne -> Mur
|
|
*/
|
|
public function murs()
|
|
{
|
|
return $this->hasMany('App\Models\Mur', 'mur_campId', 'camp_id');
|
|
}
|
|
|
|
/**
|
|
* OneToMany
|
|
* Campagne -> Panier
|
|
*/
|
|
public function paniers()
|
|
{
|
|
return $this->hasMany('App\Models\Panier', 'panier_campId', 'camp_id');
|
|
}
|
|
|
|
/**
|
|
* ManyToOne
|
|
* Campagne -> Site
|
|
*/
|
|
public function site()
|
|
{
|
|
return $this->belongsTo('App\Models\Site', 'camp_siteId', 'site_id');
|
|
}
|
|
|
|
/**
|
|
* The coupons that belong to the campagne.
|
|
*/
|
|
public function coupons()
|
|
{
|
|
return $this->belongsToMany('App\Models\Coupon', 'campagne_coupon', 'campagne_id', 'coup_id');
|
|
}
|
|
|
|
/**
|
|
* printedCoupons relation
|
|
* @return HasMany
|
|
*/
|
|
public function printedCoupons()
|
|
{
|
|
return $this->hasMany(PrintedCoupons::class, 'camp_id');
|
|
}
|
|
|
|
/**
|
|
* Basket model relation
|
|
* @return HasMany
|
|
*/
|
|
public function baskets()
|
|
{
|
|
return $this->hasMany(Basket::class);
|
|
}
|
|
}
|