33 lines
744 B
PHP
33 lines
744 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Member extends Model
|
|
{
|
|
protected $fillable = [
|
|
'unique_id', 'name', 'picture', 'gender', 'date_of_birth',
|
|
'nationality', 'weight', 'height', 'contact_info', 'social_media',
|
|
];
|
|
|
|
protected $casts = [
|
|
'contact_info' => 'array',
|
|
'social_media' => 'array',
|
|
'date_of_birth' => 'date',
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function ($member) {
|
|
// Only generate if unique_id is not set
|
|
if (empty($member->unique_id)) {
|
|
$member->unique_id = Str::random(50);
|
|
}
|
|
});
|
|
}
|
|
}
|