Completed
Push — master ( 024746...0b49f1 )
by Song
04:00
created

helpers.php ➔ array_delete()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
if (!function_exists('admin_path')) {
4
5
    /**
6
     * Get admin path.
7
     *
8
     * @param string $path
9
     *
10
     * @return string
11
     */
12
    function admin_path($path = '')
13
    {
14
        return ucfirst(config('admin.directory')).($path ? DIRECTORY_SEPARATOR.$path : $path);
15
    }
16
}
17
18
if (!function_exists('admin_url')) {
19
    /**
20
     * Get admin url.
21
     *
22
     * @param string $path
23
     * @param mixed  $parameters
24
     * @param bool   $secure
25
     *
26
     * @return string
27
     */
28
    function admin_url($path = '', $parameters = [], $secure = null)
29
    {
30
        if (\Illuminate\Support\Facades\URL::isValidUrl($path)) {
31
            return $path;
32
        }
33
34
        $secure = $secure ?: config('admin.secure');
35
36
        return url(admin_base_path($path), $parameters, $secure);
37
    }
38
}
39
40
if (!function_exists('admin_base_path')) {
41
    /**
42
     * Get admin url.
43
     *
44
     * @param string $path
45
     *
46
     * @return string
47
     */
48
    function admin_base_path($path = '')
49
    {
50
        $prefix = '/'.trim(config('admin.route.prefix'), '/');
51
52
        $prefix = ($prefix == '/') ? '' : $prefix;
53
54
        return $prefix.'/'.trim($path, '/');
55
    }
56
}
57
58
if (!function_exists('admin_toastr')) {
59
60
    /**
61
     * Flash a toastr message bag to session.
62
     *
63
     * @param string $message
64
     * @param string $type
65
     * @param array  $options
66
     *
67
     * @return string
68
     */
69
    function admin_toastr($message = '', $type = 'success', $options = [])
70
    {
71
        $toastr = new \Illuminate\Support\MessageBag(get_defined_vars());
72
73
        \Illuminate\Support\Facades\Session::flash('toastr', $toastr);
74
    }
75
}
76
77
if (!function_exists('admin_asset')) {
78
79
    /**
80
     * @param $path
81
     *
82
     * @return string
83
     */
84
    function admin_asset($path)
85
    {
86
        return asset($path, config('admin.secure'));
87
    }
88
}
89
90
if (!function_exists('array_delete')) {
91
92
    /**
93
     * Delete from array by value.
94
     *
95
     * @param array $array
96
     * @param mixed $value
97
     */
98
    function array_delete(&$array, $value)
99
    {
100
        foreach ($array as $index => $item) {
101
            if ($value == $item) {
102
                unset($array[$index]);
103
            }
104
        }
105
    }
106
}
107