Completed
Push — master ( 3e9e3c...192c50 )
by Abdelrahman
06:42 queued 04:41
created

Http/Controllers/Backend/AbilitiesController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Http\Controllers\Backend;
17
18
use Illuminate\Http\Request;
19
use Rinvex\Fort\Models\Ability;
20
use Rinvex\Fort\Contracts\AbilityRepositoryContract;
21
use Rinvex\Fort\Http\Controllers\AuthorizedController;
22
use Rinvex\Fort\Http\Requests\Backend\AbilityStoreRequest;
23
use Rinvex\Fort\Http\Requests\Backend\AbilityUpdateRequest;
24
25
class AbilitiesController extends AuthorizedController
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected $resource = 'abilities';
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected $resourceActionWhitelist = ['grant'];
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $resourceActionWhitelist exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
36
37
    /**
38
     * The ability repository instance.
39
     *
40
     * @var \Rinvex\Fort\Contracts\AbilityRepositoryContract
41
     */
42
    protected $abilityRepository;
43
44
    /**
45
     * Create a new abilities controller instance.
46
     */
47
    public function __construct(AbilityRepositoryContract $abilityRepository)
48
    {
49
        parent::__construct();
50
51
        $this->abilityRepository = $abilityRepository;
52
    }
53
54
    /**
55
     * Display a listing of the resource.
56
     *
57
     * @return \Illuminate\Http\Response
58
     */
59
    public function index()
60
    {
61
        $abilities = $this->abilityRepository->paginate(config('rinvex.fort.backend.items_per_page'));
62
63
        return view('rinvex/fort::backend/abilities.index', compact('abilities'));
64
    }
65
66
    /**
67
     * Display the specified resource.
68
     *
69
     * @param \Rinvex\Fort\Models\Ability $ability
70
     *
71
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
72
     */
73
    public function show(Ability $ability)
74
    {
75
        return view('rinvex/fort::backend/abilities.show', compact('ability'));
76
    }
77
78
    /**
79
     * Show the form for creating a new resource.
80
     *
81
     * @return \Illuminate\Http\Response
82
     */
83
    public function create()
84
    {
85
        return $this->form('create', 'store', $this->abilityRepository->createModel());
86
    }
87
88
    /**
89
     * Show the form for copying the given resource.
90
     *
91
     * @param \Rinvex\Fort\Models\Ability $ability
92
     *
93
     * @return \Illuminate\Http\Response
94
     */
95
    public function copy(Ability $ability)
96
    {
97
        return $this->form('copy', 'store', $ability);
98
    }
99
100
    /**
101
     * Show the form for editing the given resource.
102
     *
103
     * @param \Rinvex\Fort\Models\Ability $ability
104
     *
105
     * @return \Illuminate\Http\Response
106
     */
107
    public function edit(Ability $ability)
108
    {
109
        return $this->form('edit', 'update', $ability);
110
    }
111
112
    /**
113
     * Store a newly created resource in storage.
114
     *
115
     * @param \Rinvex\Fort\Http\Requests\Backend\AbilityStoreRequest $request
116
     *
117
     * @return \Illuminate\Http\Response
118
     */
119
    public function store(AbilityStoreRequest $request)
120
    {
121
        return $this->process($request);
122
    }
123
124
    /**
125
     * Update the given resource in storage.
126
     *
127
     * @param \Rinvex\Fort\Http\Requests\Backend\AbilityUpdateRequest $request
128
     * @param \Rinvex\Fort\Models\Ability                             $ability
129
     *
130
     * @return \Illuminate\Http\Response
131
     */
132
    public function update(AbilityUpdateRequest $request, Ability $ability)
133
    {
134
        return $this->process($request, $ability);
135
    }
136
137
    /**
138
     * Delete the given resource from storage.
139
     *
140
     * @param \Rinvex\Fort\Models\Ability $ability
141
     *
142
     * @return \Illuminate\Http\Response
143
     */
144
    public function delete(Ability $ability)
145
    {
146
        $result = $this->abilityRepository->delete($ability);
147
148
        return intend([
149
            'route' => 'rinvex.fort.backend.abilities.index',
150
            'with'  => ['rinvex.fort.alert.warning' => trans('rinvex/fort::backend/messages.ability.deleted', ['abilityId' => $result->id])],
151
        ]);
152
    }
153
154
    /**
155
     * Import the given resources into storage.
156
     *
157
     * @return \Illuminate\Http\Response
158
     */
159
    public function import()
160
    {
161
        //
162
    }
163
164
    /**
165
     * Export the given resources from storage.
166
     *
167
     * @return \Illuminate\Http\Response
168
     */
169
    public function export()
170
    {
171
        //
172
    }
173
174
    /**
175
     * Bulk control the given resources.
176
     *
177
     * @return \Illuminate\Http\Response
178
     */
179
    public function bulk()
180
    {
181
        //
182
    }
183
184
    /**
185
     * Show the form for create/edit/copy of the given resource.
186
     *
187
     * @param string                      $mode
188
     * @param string                      $action
189
     * @param \Rinvex\Fort\Models\Ability $ability
190
     *
191
     * @return \Illuminate\Http\Response
192
     */
193
    protected function form($mode, $action, Ability $ability)
194
    {
195
        return view('rinvex/fort::backend/abilities.form', compact('ability', 'resources', 'mode', 'action'));
196
    }
197
198
    /**
199
     * Process the form for store/update of the given resource.
200
     *
201
     * @param \Illuminate\Http\Request    $request
202
     * @param \Rinvex\Fort\Models\Ability $ability
203
     *
204
     * @return \Illuminate\Http\Response
205
     */
206
    protected function process(Request $request, Ability $ability = null)
207
    {
208
        // Store data into the entity
209
        $result = $this->abilityRepository->store($ability, $request->except(['_method', '_token', 'id']));
210
211
        // Repository `store` method returns false if no attributes
212
        // updated, happens save button clicked without chaning anything
213
        $with = ! is_null($ability)
214
            ? ($result === false
215
                ? ['rinvex.fort.alert.warning' => trans('rinvex/fort::backend/messages.ability.nothing_updated', ['abilityId' => $ability->id])]
216
                : ['rinvex.fort.alert.success' => trans('rinvex/fort::backend/messages.ability.updated', ['abilityId' => $result->id])])
217
            : ['rinvex.fort.alert.success' => trans('rinvex/fort::backend/messages.ability.created', ['abilityId' => $result->id])];
218
219
        return intend([
220
            'route' => 'rinvex.fort.backend.abilities.index',
221
            'with'  => $with,
222
        ]);
223
    }
224
}
225