Completed
Push — master ( 96b827...e9016c )
by ARCANEDEV
15:51
created

FootersController::transNotification()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 3
crap 2
1
<?php namespace Arcanesoft\Seo\Http\Controllers\Admin;
2
3
use Arcanedev\LaravelApiHelper\Traits\JsonResponses;
4
use Arcanesoft\Seo\Entities\Locales;
5
use Arcanesoft\Seo\Http\Requests\Admin\Footers\CreateFooterRequest;
6
use Arcanesoft\Seo\Http\Requests\Admin\Footers\UpdateFooterRequest;
7
use Arcanesoft\Seo\Models\Footer;
8
use Arcanesoft\Seo\Models\Page;
9
use Illuminate\Support\Facades\Log;
10
use Arcanesoft\Seo\Policies;
11
12
/**
13
 * Class     FootersController
14
 *
15
 * @package  Arcanesoft\Seo\Http\Controllers\Admin
16
 * @author   ARCANEDEV <[email protected]>
17
 */
18
class FootersController extends Controller
19
{
20
    /* -----------------------------------------------------------------
21
     |  Traits
22
     | -----------------------------------------------------------------
23
     */
24
25
    use JsonResponses;
26
27
    /* -----------------------------------------------------------------
28
     |  Constructor
29
     | -----------------------------------------------------------------
30
     */
31
32
    /**
33
     * FootersController constructor.
34
     */
35
    public function __construct()
36
    {
37
        parent::__construct();
38
39
        $this->setCurrentPage('seo-footers');
40
        $this->addBreadcrumbRoute(trans('seo::footers.titles.footers'), 'admin::seo.footers.index');
41
    }
42
43
    /* -----------------------------------------------------------------
44
     |  Main Methods
45
     | -----------------------------------------------------------------
46
     */
47
    public function index()
48
    {
49
        $this->authorize(Policies\FootersPolicy::PERMISSION_LIST);
50
51
        $footers = Footer::with(['page', 'seo'])->paginate(50);
52
53
        $this->setTitle($title = trans('seo::footers.titles.footers-list'));
54
        $this->addBreadcrumb($title);
55
56
        return $this->view('admin.footers.index', compact('footers'));
57
    }
58
59
    public function create()
60
    {
61
        $this->authorize(Policies\FootersPolicy::PERMISSION_CREATE);
62
63
        $pages   = Page::getSelectInputData();
64
        $locales = Locales::all();
65
66
        $this->setTitle($title = trans('seo::footers.titles.new-footer'));
67
        $this->addBreadcrumb($title);
68
69
        return $this->view('admin.footers.create', compact('pages', 'locales'));
70
    }
71
72
    public function store(CreateFooterRequest $request)
73
    {
74
        $this->authorize(Policies\FootersPolicy::PERMISSION_CREATE);
75
76
        $inputs = $request->only([
77
            'name', 'localization', 'uri', 'locale', 'page',
78
            'seo_title', 'seo_description', 'seo_keywords',
79
        ]);
80
81
        $footer = Footer::createOne($inputs);
82
83
        $this->transNotification('created', ['name' => $footer->name], $footer->toArray());
84
85
        return redirect()->route('admin::seo.footers.show', [$footer]);
86
    }
87
88
    public function show(Footer $footer)
89
    {
90
        $this->authorize(Policies\FootersPolicy::PERMISSION_SHOW);
91
92
        $footer->load(['page', 'seo']);
93
94
        $this->setTitle($title = trans('seo::footers.titles.footer-details'));
95
        $this->addBreadcrumb($title);
96
97
        return $this->view('admin.footers.show', compact('footer'));
98
    }
99
100
    public function edit(Footer $footer)
101
    {
102
        $this->authorize(Policies\FootersPolicy::PERMISSION_UPDATE);
103
104
        $footer->load(['page', 'seo']);
105
106
        $pages   = Page::getSelectInputData();
107
        $locales = Locales::all();
108
109
        $this->setTitle($title = trans('seo::footers.titles.edit-footer'));
110
        $this->addBreadcrumb($title);
111
112
        return $this->view('admin.footers.edit', compact('footer', 'pages', 'locales'));
113
    }
114
115
    public function update(Footer $footer, UpdateFooterRequest $request)
116
    {
117
        $this->authorize(Policies\FootersPolicy::PERMISSION_UPDATE);
118
119
        $inputs = $request->only([
120
            'name', 'localization', 'uri', 'locale', 'page',
121
            'seo_title', 'seo_description', 'seo_keywords',
122
        ]);
123
124
        $footer->updateOne($inputs);
125
126
        $this->transNotification('updated', ['name' => $footer->name], $footer->toArray());
127
128
        return redirect()->route('admin::seo.footers.show', [$footer]);
129
    }
130
131
    public function delete(Footer $footer)
132
    {
133
        $this->authorize(Policies\FootersPolicy::PERMISSION_DELETE);
134
135
        $footer->delete();
136
137
        return $this->jsonResponseSuccess([
138
            'message' => $this->transNotification('deleted', ['name' => $footer->name], $footer->toArray())
139
        ]);
140
    }
141
142
    /* -----------------------------------------------------------------
143
     |  Other Methods
144
     | -----------------------------------------------------------------
145
     */
146
147
    /**
148
     * Notify with translation.
149
     *
150
     * @param  string  $action
151
     * @param  array   $replace
152
     * @param  array   $context
153
     *
154
     * @return string
155
     */
156
    protected function transNotification($action, array $replace = [], array $context = [])
157
    {
158
        $title   = trans("seo::footers.messages.{$action}.title");
159
        $message = trans("seo::footers.messages.{$action}.message", $replace);
160
161
        Log::info($message, $context);
162
        $this->notifySuccess($message, $title);
163
164
        return $message;
165
    }
166
}
167