improved tenant identification

This commit is contained in:
Denis Duliçi
2021-04-16 00:59:43 +03:00
parent 9635e6be5d
commit 2b07442260
126 changed files with 1719 additions and 999 deletions

View File

@ -1,5 +1,6 @@
<?php
use App\Models\Common\Company;
use App\Traits\DateTime;
use App\Utilities\Date;
use App\Utilities\Widgets;
@ -67,6 +68,53 @@ if (!function_exists('show_widget')) {
}
}
if (!function_exists('company')) {
/**
* Get current/any company model.
*
* @param int|null $id
*
* @return Company|null
*/
function company($id = null)
{
$company = null;
if (is_null($id)) {
$company = Company::getCurrent();
}
if (is_numeric($id)) {
$company = Company::find($id);
}
return $company;
}
}
if (!function_exists('company_id')) {
/**
* Get id of current company.
*
* @return int
*/
function company_id()
{
return optional(company())->id;
}
}
if (!function_exists('should_queue')) {
/**
* Check if queue is enabled.
*
* @return bool
*/
function should_queue() {
return config('queue.default') != 'sync';
}
}
if (!function_exists('cache_prefix')) {
/**
* Cache system added company_id prefix.
@ -74,6 +122,6 @@ if (!function_exists('cache_prefix')) {
* @return string
*/
function cache_prefix() {
return session('company_id') . '_';
return company_id() . '_';
}
}