This repository has been archived by the owner on Nov 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
/
helpers.php
128 lines (115 loc) · 3.14 KB
/
helpers.php
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
127
128
<?php
if (!function_exists('backpack_url')) {
/**
* Appends the configured backpack prefix and returns
* the URL using the standard Laravel helpers.
*
* @param $path
*
* @return string
*/
function backpack_url($path = null)
{
$path = !$path || (substr($path, 1, 1) == '/') ? $path : '/'.$path;
return url(config('backpack.base.route_prefix', 'admin').$path);
}
}
if (!function_exists('backpack_authentication_column')) {
/**
* Return the username column name.
* The Laravel default (and Backpack default) is 'email'.
*
* @return string
*/
function backpack_authentication_column()
{
return config('backpack.base.authentication_column', 'email');
}
}
if (!function_exists('backpack_users_have_email')) {
/**
* Check if the email column is present on the user table.
*
* @return string
*/
function backpack_users_have_email()
{
$user_model_fqn = config('backpack.base.user_model_fqn');
$user = new $user_model_fqn();
return \Schema::hasColumn($user->getTable(), 'email');
}
}
if (!function_exists('backpack_avatar')) {
/**
* Returns the avatar URL of a user.
*
* @param $user
*
* @return string
*/
function backpack_avatar_url($user)
{
$placeholder = 'https://placehold.it/160x160/00a65a/ffffff/&text='.$user->name[0];
switch (config('backpack.base.avatar_type')) {
case 'gravatar':
if (backpack_users_have_email()) {
return Gravatar::fallback('https://placehold.it/160x160/00a65a/ffffff/&text='.$user->name[0])->get($user->email);
} else {
return $placeholder;
}
break;
case 'placehold':
return $placeholder;
break;
default:
return $user->{config('backpack.base.avatar_type')};
break;
}
}
}
if (!function_exists('backpack_middleware')) {
/**
* Return the key of the middleware used across Backpack.
* That middleware checks if the visitor is an admin.
*
* @param $path
*
* @return string
*/
function backpack_middleware()
{
return config('backpack.base.middleware_key', 'admin');
}
}
if (!function_exists('backpack_guard_name')) {
/*
* Returns the name of the guard defined
* by the application config
*/
function backpack_guard_name()
{
return config('backpack.base.guard', config('auth.defaults.guard'));
}
}
if (!function_exists('backpack_auth')) {
/*
* Returns the user instance if it exists
* of the currently authenticated admin
* based off the defined guard.
*/
function backpack_auth()
{
return \Auth::guard(backpack_guard_name());
}
}
if (!function_exists('backpack_user')) {
/*
* Returns back a user instance without
* the admin guard, however allows you
* to pass in a custom guard if you like.
*/
function backpack_user()
{
return backpack_auth()->user();
}
}