Passed
Push — 5.0.0 ( c86c37...f3ec4d )
by Fèvre
06:46
created

SettingController::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 15
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Controllers\Admin;
6
7
use Illuminate\Contracts\View\View;
8
use Illuminate\Http\RedirectResponse;
9
use Illuminate\Http\Request;
10
use Xetaravel\Models\Repositories\SettingRepository;
11
use Xetaravel\Models\Setting;
12
use Xetaravel\Settings\Settings;
13
14
class SettingController extends Controller
15
{
16
    /**
17
     * Show all the settings.
18
     *
19
     * @return View
20
     */
21
    public function index(): View
22
    {
23
        $this->authorize('viewAny', Setting::class);
24
25
        $settings = Setting::whereNull('model_type')
26
            ->whereNull('model_id')
27
            ->get();
28
29
        $breadcrumbs = $this->breadcrumbs->addCrumb(
30
            '<svg class="w-5 h-5 mr-2" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M352 320c88.4 0 160-71.6 160-160c0-15.3-2.2-30.1-6.2-44.2c-3.1-10.8-16.4-13.2-24.3-5.3l-76.8 76.8c-3 3-7.1 4.7-11.3 4.7L336 192c-8.8 0-16-7.2-16-16l0-57.4c0-4.2 1.7-8.3 4.7-11.3l76.8-76.8c7.9-7.9 5.4-21.2-5.3-24.3C382.1 2.2 367.3 0 352 0C263.6 0 192 71.6 192 160c0 19.1 3.4 37.5 9.5 54.5L19.9 396.1C7.2 408.8 0 426.1 0 444.1C0 481.6 30.4 512 67.9 512c18 0 35.3-7.2 48-19.9L297.5 310.5c17 6.2 35.4 9.5 54.5 9.5zM80 408a24 24 0 1 1 0 48 24 24 0 1 1 0-48z"></path></svg>
31
                        Settings',
32
            route('admin.setting.index')
33
        );
34
35
        return view('Admin.setting.index', compact('breadcrumbs', 'settings'));
36
    }
37
38
    /**
39
     * Update the settings.
40
     *
41
     * @param Settings $settings
42
     * @param Request $request
43
     *
44
     * @return RedirectResponse
45
     */
46
    public function update(Settings $settings, Request $request)
47
    {
48
        $this->authorize('update', Setting::class);
49
50
        $updated = SettingRepository::update($settings, $request->all());
51
52
        if (!$updated) {
53
            return redirect()
54
                ->back()
0 ignored issues
show
Bug introduced by
The method back() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
                ->/** @scrutinizer ignore-call */ back()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
                ->error('Error while saving settings.');
56
        }
57
58
        return redirect()
59
            ->back()
60
            ->success('All settings has been updated successfully !');
61
    }
62
}
63