@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\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @if($hasSoftDelete)use Illuminate\Database\Eloquent\SoftDeletes; @endif 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; @if($translatable->count() > 0)use Smarteknoloji\Translatable\Traits\HasTranslations; @endif @if($hasRoles)use Spatie\Permission\Traits\HasRoles; @endif class {{ $modelBaseName }} extends Authenticatable implements CanActivateContract { use HasApiTokens, HasFactory, Notifiable; @if($hasSoftDelete)use SoftDeletes; @endif @if($hasRoles)use HasRoles; @endif @if($translatable->count() > 0)use HasTranslations; @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 array $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']; /* ************************ ACCESSOR ************************* */ /** * Get resource url to generate edit. */ protected function resourceUrl(): Attribute { return Attribute::make( get: fn () => url('/admin/{{ $resource }}/'.$this->getKey()) ); } public function getFullNameAttribute() { return $this->first_name." ".$this->last_name; } /** * Send the password reset notification. * * {{'@'}}param string $token * {{'@'}}return void */ public function sendPasswordResetNotification($token) { $this->notify(app( ResetPassword::class, ['token' => $token])); } @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 }