<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @method static where(string $string, string $uid)
* @method static create(array $array)
* @method static insert(array $template_data)
*/
class Templates extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'user_id',
'message',
'status',
];
/**
*
* @var string[]
*/
protected $casts = [
'status' => 'boolean',
];
/**
* Bootstrap any application services.
*/
public static function boot()
{
parent::boot();
// Create uid when creating list.
static::creating(function ($item) {
// Create new uid
$uid = uniqid();
while (self::where('uid', $uid)->count() > 0) {
$uid = uniqid();
}
$item->uid = $uid;
});
}
/**
* get route key by uid
*
* @return string
*/
public function getRouteKeyName(): string
{
return 'uid';
}
/**
* @return string
*/
public function __toString(): string
{
return $this->name;
}
}