89 lines
2.4 KiB
PHP
89 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Participation.
|
|
*
|
|
* @property string $ip IP
|
|
* @property string $sticker Path of the sticker file
|
|
* @property string $ticket Path of the ticket file
|
|
* @property string $barcode Path of the barcode file
|
|
* @property-read \Illuminate\Support\Carbon $created_at Creation Date.
|
|
* @property-read \Illuminate\Support\Carbon $updated_at Last update Date.
|
|
*
|
|
* @property-read string|null $code_ean Accessor for code_ean, from product table.
|
|
*
|
|
* @property-read \App\Models\Customer $customer Associated customer.
|
|
* @property-read \App\Models\Code $code Associated code.
|
|
* @property-read \App\Models\Product $product Associated product.
|
|
* @property-read \App\Models\InstantWin $instantWin Associated instantWin.
|
|
* @property-read \App\Models\Reduction $reduction Associated reduction.
|
|
*/
|
|
class Participation extends Model
|
|
{
|
|
/**
|
|
* BelongsTo User relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
/**
|
|
* BelongsTo Codes relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function code()
|
|
{
|
|
return $this->belongsTo(Code::class, 'code_unique_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo Product relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function product()
|
|
{
|
|
return $this->belongsTo(Product::class);
|
|
}
|
|
|
|
/**
|
|
* One to one InstantWin relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function instantWin()
|
|
{
|
|
return $this->hasOne(InstantWin::class);
|
|
}
|
|
|
|
/**
|
|
* One to one Reduction relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function reduction()
|
|
{
|
|
return $this->hasOne(Reduction::class);
|
|
}
|
|
|
|
/**
|
|
* Accessor for code_ean, from product table.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Casts\Attribute;
|
|
*/
|
|
public function codeEan(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => optional($this->product)->code_ean,
|
|
);
|
|
}
|
|
}
|