129 lines
3.2 KiB
PHP
Executable File
129 lines
3.2 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* SysCMS - Content Management System
|
|
*
|
|
* Copyright (c) 2025 Marco Costa
|
|
* All rights reserved.
|
|
*
|
|
* Author: Marco Costa
|
|
* Email: contato@syspanel.com.br
|
|
* Project: SysCMS
|
|
*
|
|
* This software is licensed, not sold.
|
|
* Permission is granted to use this software
|
|
* subject to the terms of the SysCMS Commercial License.
|
|
*
|
|
* Redistribution, sublicensing, resale, or
|
|
* disclosure of this software, in whole or in part,
|
|
* is strictly prohibited without prior written permission.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Modules\Company\Models\Company;
|
|
|
|
class RolePermission extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'role_permissions';
|
|
|
|
/**
|
|
* The primary key associated with table.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'role_permissions_id';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'role_permissions_role',
|
|
'role_permissions_bus_id',
|
|
'role_permissions_permission',
|
|
'role_permissions_created_by'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be mutated to dates.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dates = [
|
|
'created_at',
|
|
'updated_at'
|
|
];
|
|
|
|
/**
|
|
* Get the company that owns the role permission.
|
|
*/
|
|
public function company(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Company::class, 'role_permissions_bus_id');
|
|
}
|
|
|
|
/**
|
|
* Get the user who created the role permission.
|
|
*/
|
|
public function createdByUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\Modules\Auth\Models\User::class, 'role_permissions_created_by');
|
|
}
|
|
|
|
/**
|
|
* Scope to get permissions for a specific role.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param string $role
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeForRole($query, string $role)
|
|
{
|
|
return $query->where('role_permissions_role', $role);
|
|
}
|
|
|
|
/**
|
|
* Scope to get permissions for a specific company.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param int $companyId
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeForCompany($query, int $companyId)
|
|
{
|
|
return $query->where('role_permissions_bus_id', $companyId);
|
|
}
|
|
|
|
/**
|
|
* Scope to get permissions with specific permission.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param string $permission
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
public function scopeWithPermission($query, string $permission)
|
|
{
|
|
return $query->where('role_permissions_permission', $permission);
|
|
}
|
|
} |