74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Basket
|
|
*
|
|
* @property integer $id Basket Id.
|
|
* @property string $reference Basket reference.
|
|
* @property integer $customer_id Basket customer Id.
|
|
* @property integer $campaign_id Basket campaign Id.
|
|
*
|
|
* @property-read \Carbon\Carbon $created_at Created date.
|
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
|
*
|
|
* * RELATIONS
|
|
* @property-read \App\Models\Customer $customer The customer that owns the Basket.
|
|
* @property-read \App\Models\BasketsContent $content The content owned by the Basket.
|
|
*/
|
|
class Basket extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* Fillable
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'reference',
|
|
'customer_id',
|
|
'campaign_id'
|
|
];
|
|
|
|
/**
|
|
* The "booted" method of the model.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (Basket $basket) {
|
|
$basket->reference = Str::ulid();
|
|
});
|
|
}
|
|
|
|
// * RELATIONS
|
|
|
|
/**
|
|
* Get the content owned by the Basket
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function content(): HasMany
|
|
{
|
|
return $this->hasMany(BasketsContent::class);
|
|
}
|
|
|
|
/**
|
|
* Get the customer that owns the Basket
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function customer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
}
|