akaunting/app/Utilities/helpers.php

68 lines
1.3 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
use App\Traits\DateTime;
2020-03-25 20:21:42 +03:00
use App\Utilities\Date;
2019-12-31 02:20:10 +03:00
use App\Utilities\Widgets;
2019-11-16 10:21:14 +03:00
if (!function_exists('user')) {
/**
* Get the authenticated user.
*
* @return \App\Models\Auth\User
*/
function user()
{
// Get user from api/web
if (request()->is('api/*')) {
$user = app('Dingo\Api\Auth\Auth')->user();
} else {
$user = auth()->user();
}
return $user;
}
}
if (!function_exists('company_date')) {
/**
* Format the given date based on company settings.
*
* @return string
*/
function company_date($date)
{
$date_time = new class() {
use DateTime;
};
return Date::parse($date)->format($date_time->getCompanyDateFormat());
}
}
2019-12-31 02:20:10 +03:00
if (!function_exists('show_widget')) {
/**
2020-01-04 11:49:59 +03:00
* Show a widget.
2019-12-31 02:20:10 +03:00
*
* @return string
*/
2020-01-04 11:49:59 +03:00
function show_widget()
2019-12-31 02:20:10 +03:00
{
2020-01-04 11:49:59 +03:00
$arguments = func_get_args();
$model = array_shift($arguments);
return Widgets::show($model, ...$arguments);
2019-12-31 02:20:10 +03:00
}
}
if (!function_exists('cache_prefix')) {
/**
* Cache system added company_id prefix.
*
* @return string
*/
function cache_prefix() {
return session('company_id') . '_';
}
}