@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 @if($hasSoftDelete)use Illuminate\Database\Eloquent\SoftDeletes; @endif @if (count($relations['belongsToMany']))use Illuminate\Database\Eloquent\Relations\BelongsToMany; @endif // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Contracts\Routing\UrlGenerator; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use Smarteknoloji\AdminAuth\Activation\Contracts\CanActivate as CanActivateContract; use Smarteknoloji\AdminAuth\Activation\Traits\CanActivate; use Smarteknoloji\AdminAuth\Notifications\ResetPassword; use Smarteknoloji\Media\HasMedia\AutoProcessMediaTrait; use Smarteknoloji\Media\HasMedia\HasMediaCollectionsTrait; use Smarteknoloji\Media\HasMedia\HasMediaThumbsTrait; use Smarteknoloji\Media\HasMedia\ProcessMediaTrait; @if($translatable->count() > 0)use Smarteknoloji\Translatable\Traits\HasTranslations; @endif use Spatie\Image\Exceptions\InvalidManipulation; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; @if($hasRoles)use Spatie\Permission\Traits\HasRoles; @endif class {{ $modelBaseName }} extends Authenticatable implements CanActivateContract, HasMedia { use HasApiTokens, HasFactory, Notifiable; use CanActivate; @if($translatable->count() > 0) use HasTranslations; @endif use AutoProcessMediaTrait; use HasMediaCollectionsTrait; use HasMediaThumbsTrait; @if($hasRoles) use HasRoles; @endif use ProcessMediaTrait; @if($hasSoftDelete) use SoftDeletes; @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)/** * 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 $translatable = [ @foreach($translatable as $translatableField) '{{ $translatableField }}', @endforeach ]; @endif @if (!$timestamps)public $timestamps = false; @endif /** * The attributes that should be cast. * * {{'@var array'}} */ protected $casts = [ 'last_login_at' => 'datetime', 'password' => 'hashed', ]; /** * The accessors to append to the model's array form. * * @var array */ protected $appends = ['full_name', 'resource_url', 'avatar_thumb_url']; /* ************************ ACCESSOR ************************* */ /** * Get resource url to generate edit. */ protected function resourceUrl(): Attribute { return Attribute::make( get: fn () => url('/admin/{{ $resource }}/'.$this->getKey()) ); } /** * Full name for admin user * * {{'@'}}return string */ public function getFullNameAttribute(): string { return $this->first_name." ".$this->last_name; } /** * Get url of avatar image. * * {{'@'}}return string|null */ public function getAvatarThumbUrlAttribute(): ?string { return $this->getFirstMediaUrl('avatar', 'thumb_150') ?: null; } /** * Send the password reset notification. * * {{'@'}}param string $token * {{'@'}}return void */ public function sendPasswordResetNotification($token) { $this->notify(app( ResetPassword::class, ['token' => $token])); } /* ************************ MEDIA ************************ */ /** * Register media collections */ public function registerMediaCollections(): void { $this->addMediaCollection('avatar') ->accepts('image/*'); } /** * Register media conversions * * @throws InvalidManipulation */ public function registerMediaConversions(Media $media = null): void { $this->autoRegisterThumb200(); $this->addMediaConversion('thumb_75') ->width(75) ->height(75) ->fit('crop', 75, 75) ->optimize() ->performOnCollections('avatar') ->nonQueued(); $this->addMediaConversion('thumb_150') ->width(150) ->height(150) ->fit('crop', 150, 150) ->optimize() ->performOnCollections('avatar') ->nonQueued(); } /** * Auto register thumb overridden */ public function autoRegisterThumb200() { $this->getMediaCollections()->filter->isImage()->each(function ($mediaCollection) { $this->addMediaConversion('thumb_200') ->width(200) ->height(200) ->fit('crop', 200, 200) ->optimize() ->performOnCollections($mediaCollection->getName()) ->nonQueued(); }); } @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 }