| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Kalnoy\Nestedset\NodeTrait;
- class Permission extends Model
- {
- use HasFactory, SoftDeletes, NodeTrait;
- /**
- * The attributes that are mass assignable.
- *
- * @var array<int, string>
- */
- protected $fillable = [
- 'name',
- 'bits',
- 'description',
- 'parent_id',
- ];
- /**
- * The attributes that should be cast.
- *
- * @return array<string, string>
- */
- protected function casts(): array
- {
- return [
- 'parent_id' => 'integer',
- ];
- }
- public function children(): HasMany
- {
- return $this->hasMany(Permission::class, 'parent_id');
- }
- public function parent(): BelongsTo
- {
- return $this->belongsTo(Permission::class, 'parent_id');
- }
- }
|