Files
HRM-System/app/Models/BaseAuthenticatable.php

37 lines
876 B
PHP

<?php
namespace App\Models;
use App\Traits\AutoApplyPermissionCheck;
use Illuminate\Foundation\Auth\User as Authenticatable;
class BaseAuthenticatable extends Authenticatable
{
use AutoApplyPermissionCheck;
/**
* Get the database connection name for the model.
*
* @return string|null
*/
public function getConnectionName()
{
if (function_exists('tenant') && tenant()) {
return 'tenant';
}
return parent::getConnectionName();
}
/**
* Scope a query to apply permission-based filtering
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeWithPermissionCheck($query)
{
$tableName = $this->getTable();
return $this->applyPermissionScope($query, $tableName);
}
}