*/ protected $fillable = [ 'reference', 'first_name', 'last_name', 'email', 'address', 'city', 'postcode', 'file', 'message', 'type', 'status', 'brand_id', 'subject_id', 'customer_id', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => ClaimType::class, 'status' => ClaimStatus::class, ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { static::created(function (self $model) { $model->reference = self::encodeIntegerToBase36($model->getKey()); $model->saveOrFail(); }); } // * RELATIONS /** * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Brand::class); } /** * ClaimSubject subject belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function claimSubject(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(ClaimSubject::class); } /** * Customer subject belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function customer(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Customer::class); } /** * ClaimMessage has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function claimMessages(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(ClaimMessage::class); } // * METHODS /** * Convert the integer to base 36 and make uppercase. * * @param integer $int * @return string */ public static function encodeIntegerToBase36(int $int): string { return strtoupper(base_convert($int, 10, 36)); } /** * Convert back to base 10 from base 36, case insensitive. * * @param string $str * @return string */ public static function decodeBase36ToInteger(string $str): string { return base_convert(strtolower($str), 36, 10); } }