Completed
Push — master ( 1a56f9...9378a2 )
by Mohamed
17:07
created

functions.php ➔ addMediaTo()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 3
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
if (! function_exists('setting')) {
4
    function setting($key = null, $default = null) {
5
        if ($key === null) {
6
            return new Microboard\Models\Setting;
7
        }
8
9
        return \Microboard\Models\Setting::getValueFor($key, $default);
10
    }
11
}
12
13
if (! function_exists('addMediaTo')) {
14
    function addMediaTo(\Spatie\MediaLibrary\HasMedia $model, $collection = 'default', $input = 'file') {
15
        if (request()->has($input)) {
16
            $file = request()->input($input);
17
18
            if (is_array($file)) {
19
                foreach ($file as $_file) {
20
                    $model->addMedia(storage_path("tmp/{$_file}"))->toMediaCollection($collection);
21
                }
22
            } else {
23
                $model->addMedia(storage_path("tmp/{$file}"))->toMediaCollection($collection);
24
            }
25
        }
26
    }
27
}
28