Add CatalogPlugin scaffold and EvCompany resource (T2.0, T2.1)
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).
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?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',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user