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

71 lines
1.9 KiB
PHP
Raw Normal View History

2023-09-13 16:48:17 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2023-11-24 15:49:44 +01:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2023-09-13 16:48:17 +02:00
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;
2023-11-24 15:49:44 +01:00
/**
* Basket
*
* @property integer $id Basket Id.
* @property string $reference Basket Reference.
* @property integer $customer_id Basket Cutomer 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 content owned by the Basket
* @property-read \App\Models\BasketsContent $content The customer that owns the Basket
*/
2023-09-13 16:48:17 +02:00
class Basket extends Model
{
use HasFactory;
2023-11-24 15:35:08 +01:00
/**
* Fillable
*
* @var string[]
*/
2023-09-13 16:48:17 +02:00
protected $fillable = [
'reference',
'customer_id',
'campaign_id'
];
2023-11-24 15:35:08 +01:00
/**
* Get the content owned by the Basket
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function content(): HasMany
2023-09-13 16:48:17 +02:00
{
return $this->hasMany(BasketsContent::class);
}
2023-11-24 15:49:44 +01:00
/**
* Get the customer that owns the Basket
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
2023-09-13 16:48:17 +02:00
/**
* The "booted" method of the model.
2023-11-24 15:35:08 +01:00
*
* @return void
2023-09-13 16:48:17 +02:00
*/
protected static function booted(): void
{
static::creating(function (Basket $basket) {
$basket->reference = Str::ulid();
});
}
}