6039d25c6d
Registers CatalogPlugin with the admin panel so catalog Filament resources auto-discover, and adds the EvCompany model/migration/ factory plus its Filament resource (auto-generated slug on create).
60 lines
1.2 KiB
PHP
60 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Catalog\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
use Modules\Catalog\Database\Factories\EvCompanyFactory;
|
|
|
|
class EvCompany extends Model
|
|
{
|
|
/** @use HasFactory<EvCompanyFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'mm_name',
|
|
'slug',
|
|
'description',
|
|
'mm_description',
|
|
'contact',
|
|
'address',
|
|
'logo',
|
|
'is_active',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $evCompany): void {
|
|
if (filled($evCompany->slug)) {
|
|
return;
|
|
}
|
|
|
|
$slug = Str::slug($evCompany->name);
|
|
$uniqueSlug = $slug;
|
|
$suffix = 1;
|
|
|
|
while (static::where('slug', $uniqueSlug)->exists()) {
|
|
$uniqueSlug = "{$slug}-{$suffix}";
|
|
$suffix++;
|
|
}
|
|
|
|
$evCompany->slug = $uniqueSlug;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
}
|