@php echo "filter(function($belongsToMany) { return $belongsToMany['related_table'] == 'roles'; })->count() > 0; $relations['belongsToMany'] = $relations['belongsToMany']->reject(function($belongsToMany) { return $belongsToMany['related_table'] == 'roles'; }); } @endphp use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; @if($fillable)@foreach($fillable as $fillableColumn) @if($fillableColumn === "created_by_admin_user_id")use Smarteknoloji\Smartekcms\Traits\CreatedByAdminUserTrait; @elseif($fillableColumn === "updated_by_admin_user_id")use Smarteknoloji\Smartekcms\Traits\UpdatedByAdminUserTrait; @elseif($fillableColumn === "slug")use Spatie\Sluggable\HasTranslatableSlug; use Spatie\Sluggable\SlugOptions; @endif @endforeach @endif @if($hasSoftDelete)use Illuminate\Database\Eloquent\SoftDeletes; @endif @if (isset($relations['belongsToMany']) && count($relations['belongsToMany'])) use Illuminate\Database\Eloquent\Relations\BelongsToMany; @endif @if($hasRoles)use Spatie\Permission\Traits\HasRoles; @endif @if($translatable->count() > 0)use Smarteknoloji\Translatable\Traits\HasTranslations; @endif @if($hasMedia || $hasTransMedia) use Smarteknoloji\Media\GetMedia\GetFirstMediaTrait; use Smarteknoloji\Media\HasMedia\AutoProcessMediaTrait; use Smarteknoloji\Media\HasMedia\HasMediaCollectionsTrait; use Smarteknoloji\Media\HasMedia\HasMediaThumbsTrait; use Smarteknoloji\Media\HasMedia\ProcessMediaTrait; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; @endif class {{ $modelBaseName }} extends Model @if($hasMedia || $hasTransMedia)implements HasMedia @endif { @if($hasSoftDelete) use SoftDeletes; @endif @if($hasRoles)use HasRoles; @endif @if($translatable->count() > 0) use HasTranslations; @endif @if($fillable)@foreach($fillable as $fillableColumn) @if($fillableColumn === "created_by_admin_user_id") use CreatedByAdminUserTrait; @elseif($fillableColumn === "updated_by_admin_user_id") use UpdatedByAdminUserTrait; @elseif($fillableColumn === "slug") use HasTranslatableSlug; @endif @endforeach @endif @if($hasMedia || $hasTransMedia) //Media use ProcessMediaTrait; use AutoProcessMediaTrait; use HasMediaCollectionsTrait; use HasMediaThumbsTrait; use GetFirstMediaTrait; @endif @if (!is_null($tableName))protected $table = '{{ $tableName }}'; @endif @if ($fillable)/** * The attributes that are mass assignable. * * {{'@var array'}} */ protected $fillable = [ @foreach($fillable as $f) '{{ $f }}', @endforeach ]; @endif @if ($hidden && count($hidden) > 0)/** * The attributes that should be hidden for serialization. * * {{'@var array'}} */ protected $hidden = [ @foreach($hidden as $h) '{{ $h }}', @endforeach ]; @endif @if ($translatable->count() > 0)/** * The attributes that are translatable. * * {{'@var array'}} */ public array $translatable = [ @foreach($translatable as $translatableField) '{{ $translatableField }}', @endforeach ]; @endif @if (!$timestamps)public $timestamps = false; @endif @if($hasPublishedAt) /** * The attributes that should be cast. * * {{'@var array'}} */ protected $casts = [ 'published_at' => 'datetime:Y-m-d H:i:s', ]; @endif /** * The accessors to append to the model's array form. * * @var array */ protected $appends = ['resource_url']; /* ************************ ACCESSOR ************************* */ /** * Get resource url to generate edit. */ protected function resourceUrl(): Attribute { return Attribute::make( get: fn () => url('/admin/{{ $resource }}/'.$this->getKey()) ); } @if($hasMedia || $hasTransMedia) /** * Register media collections. */ public function registerMediaCollections(): void { @if($hasMedia) @foreach($mediaNames as $collectionName) $this->addMediaCollection('{{ $collectionName }}') ->accepts('image/*') ->maxNumberOfFiles(1); @endforeach @endif @if($hasTransMedia) $lang = config("translatable.locales"); foreach ($lang as $value) { @foreach($transMediaNames as $collectionName) $this->addMediaCollection('{{ $collectionName }}' . $value) ->accepts('image/*') ->maxNumberOfFiles(1); @endforeach } @endif } /** * Thumbnail */ public function registerMediaConversions(Media $media = null): void { $this->autoRegisterThumb200(); } @endif @if($fillable) @foreach($fillable as $fillableColumn) @if($fillableColumn === "slug") /** * Get the options for generating the slug. */ public function getSlugOptions(): SlugOptions { return SlugOptions::create() ->generateSlugsFrom('title') ->saveSlugsTo("slug"); } @endif @endforeach @endif @if (count($relations)) /* ************************ RELATIONS ************************ */ @if (count($relations['belongsToMany'])) @foreach($relations['belongsToMany'] as $belongsToMany)/** * Relation to {{ $belongsToMany['related_model_name_plural'] }} */ public function {{ $belongsToMany['related_table'] }}(): BelongsToMany { return $this->belongsToMany({{ $belongsToMany['related_model_class'] }}, '{{ $belongsToMany['relation_table'] }}', '{{ $belongsToMany['foreign_key'] }}', '{{ $belongsToMany['related_key'] }}'); } @endforeach @endif @endif}