| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?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;
- protected $guarded = ['id'];
- /**
- * The attributes that should be cast.
- *
- * @return array<string, string>
- */
- protected function casts(): array
- {
- return [
- 'parent_id' => 'integer',
- 'bits' => 'integer',
- ];
- }
- public function children(): HasMany
- {
- return $this->hasMany(Permission::class, 'parent_id');
- }
- public function parent(): BelongsTo
- {
- return $this->belongsTo(Permission::class, 'parent_id');
- }
- public function userTypePermissions(): HasMany
- {
- return $this->hasMany(UserTypePermission::class);
- }
- }
|