helpers.php
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* Global helpers file with misc functions.
*/
if (! function_exists('app_name')) {
/**
* Helper to grab the application name.
*
* @return mixed
*/
function app_name()
{
return config('app.name');
}
}
if (! function_exists('company_name')) {
/**
* Helper to grab the application name
*
* @return mixed
*/
function company_name()
{
return config('app.company_name');
}
}
if (! function_exists('access')) {
/**
* Access (lol) the Access:: facade as a simple function.
*/
function access()
{
return app('access');
}
}
if (! function_exists('history')) {
/**
* Access the history facade anywhere.
*/
function history()
{
return app('history');
}
}
if (! function_exists('gravatar')) {
/**
* Access the gravatar helper.
*/
function gravatar()
{
return app('gravatar');
}
}
if (! function_exists('includeRouteFiles')) {
/**
* Loops through a folder and requires all PHP files
* Searches sub-directories as well.
*
* @param $folder
*/
function includeRouteFiles($folder)
{
try {
$rdi = new recursiveDirectoryIterator($folder);
$it = new recursiveIteratorIterator($rdi);
while ($it->valid()) {
if (! $it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') {
require $it->key();
}
$it->next();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
if (! function_exists('getRtlCss')) {
/**
* The path being passed is generated by Laravel Mix manifest file
* The webpack plugin takes the css filenames and appends rtl before the .css extension
* So we take the original and place that in and send back the path.
*
* @param $path
*
* @return string
*/
function getRtlCss($path)
{
$path = explode('/', $path);
$filename = end($path);
array_pop($path);
$filename = rtrim($filename, '.css');
return implode('/', $path).'/'.$filename.'.rtl.css';
}
}
if (! function_exists('homeRoute')) {
/**
* Return the route to the "home" page depending on authentication/authorization status.
*
* @return string
*/
function homeRoute()
{
if (access()->allow('view-backend')) {
return 'admin.dashboard';
} elseif (auth()->check()) {
return 'frontend.user.dashboard';
}
return 'frontend.index';
}
}