Permission.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. use Kalnoy\Nestedset\NodeTrait;
  9. class Permission extends Model
  10. {
  11. use HasFactory, SoftDeletes, NodeTrait;
  12. /**
  13. * The attributes that are mass assignable.
  14. *
  15. * @var array<int, string>
  16. */
  17. protected $fillable = [
  18. 'name',
  19. 'bits',
  20. 'description',
  21. 'parent_id',
  22. ];
  23. /**
  24. * The attributes that should be cast.
  25. *
  26. * @return array<string, string>
  27. */
  28. protected function casts(): array
  29. {
  30. return [
  31. 'parent_id' => 'integer',
  32. ];
  33. }
  34. public function children(): HasMany
  35. {
  36. return $this->hasMany(Permission::class, 'parent_id');
  37. }
  38. public function parent(): BelongsTo
  39. {
  40. return $this->belongsTo(Permission::class, 'parent_id');
  41. }
  42. }