Completed
Push — master ( 782d0f...3c99c3 )
by Song
02:55
created

helpers.php ➔ admin_warning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\MessageBag;
4
5
if (!function_exists('admin_path')) {
6
7
    /**
8
     * Get admin path.
9
     *
10
     * @param string $path
11
     *
12
     * @return string
13
     */
14
    function admin_path($path = '')
15
    {
16
        return ucfirst(config('admin.directory')).($path ? DIRECTORY_SEPARATOR.$path : $path);
17
    }
18
}
19
20
if (!function_exists('admin_url')) {
21
    /**
22
     * Get admin url.
23
     *
24
     * @param string $path
25
     * @param mixed  $parameters
26
     * @param bool   $secure
27
     *
28
     * @return string
29
     */
30
    function admin_url($path = '', $parameters = [], $secure = null)
31
    {
32
        if (\Illuminate\Support\Facades\URL::isValidUrl($path)) {
33
            return $path;
34
        }
35
36
        $secure = $secure ?: config('admin.secure');
37
38
        return url(admin_base_path($path), $parameters, $secure);
39
    }
40
}
41
42
if (!function_exists('admin_base_path')) {
43
    /**
44
     * Get admin url.
45
     *
46
     * @param string $path
47
     *
48
     * @return string
49
     */
50
    function admin_base_path($path = '')
51
    {
52
        $prefix = '/'.trim(config('admin.route.prefix'), '/');
53
54
        $prefix = ($prefix == '/') ? '' : $prefix;
55
56
        return $prefix.'/'.trim($path, '/');
57
    }
58
}
59
60 View Code Duplication
if (!function_exists('admin_toastr')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
62
    /**
63
     * Flash a toastr message bag to session.
64
     *
65
     * @param string $message
66
     * @param string $type
67
     * @param array  $options
68
     */
69
    function admin_toastr($message = '', $type = 'success', $options = [])
70
    {
71
        $toastr = new MessageBag(get_defined_vars());
72
73
        session()->flash('toastr', $toastr);
74
    }
75
}
76
77
if (!function_exists('admin_success')) {
78
79
    /**
80
     * Flash a success message bag to session.
81
     *
82
     * @param string $title
83
     * @param string $message
84
     */
85
    function admin_success($title, $message = '')
86
    {
87
        admin_info($title, $message, 'success');
88
    }
89
}
90
91
if (!function_exists('admin_error')) {
92
93
    /**
94
     * Flash a error message bag to session.
95
     *
96
     * @param string $title
97
     * @param string $message
98
     */
99
    function admin_error($title, $message = '')
100
    {
101
        admin_info($title, $message, 'error');
102
    }
103
}
104
105
if (!function_exists('admin_warning')) {
106
107
    /**
108
     * Flash a warning message bag to session.
109
     *
110
     * @param string $title
111
     * @param string $message
112
     */
113
    function admin_warning($title, $message = '')
114
    {
115
        admin_info($title, $message, 'warning');
116
    }
117
}
118
119 View Code Duplication
if (!function_exists('admin_info')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
121
    /**
122
     * Flash a message bag to session.
123
     *
124
     * @param string $title
125
     * @param string $message
126
     * @param string $type
127
     */
128
    function admin_info($title, $message = '', $type = 'info')
129
    {
130
        $message = new MessageBag(get_defined_vars());
131
132
        session()->flash($type, $message);
133
    }
134
}
135
136
if (!function_exists('admin_asset')) {
137
138
    /**
139
     * @param $path
140
     *
141
     * @return string
142
     */
143
    function admin_asset($path)
144
    {
145
        return asset($path, config('admin.secure'));
146
    }
147
}
148
149
if (!function_exists('array_delete')) {
150
151
    /**
152
     * Delete from array by value.
153
     *
154
     * @param array $array
155
     * @param mixed $value
156
     */
157
    function array_delete(&$array, $value)
158
    {
159
        foreach ($array as $index => $item) {
160
            if ($value == $item) {
161
                unset($array[$index]);
162
            }
163
        }
164
    }
165
}
166