1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Modules\DummyModule\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Modules\Core\BaseClasses\BaseApiController; |
6
|
|
|
use App\Modules\DummyModule\Repositories\DummyRepository; |
7
|
|
|
use App\Modules\Core\Utl\CoreConfig; |
8
|
|
|
use App\Modules\DummyModule\Http\Requests\InsertDummy; |
9
|
|
|
use App\Modules\DummyModule\Http\Requests\UpdateDummy; |
10
|
|
|
|
11
|
|
View Code Duplication |
class DummyController extends BaseApiController |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* List of all route actions that the base api controller |
15
|
|
|
* will skip permissions check for them. |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $skipPermissionCheck = []; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* List of all route actions that the base api controller |
22
|
|
|
* will skip login check for them. |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected $skipLoginCheck = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Init new object. |
29
|
|
|
* |
30
|
|
|
* @param DummyRepository $repo |
31
|
|
|
* @param CoreConfig $config |
32
|
|
|
* @return void |
|
|
|
|
33
|
|
|
*/ |
34
|
|
|
public function __construct(DummyRepository $repo, CoreConfig $config) |
35
|
|
|
{ |
36
|
|
|
parent::__construct($repo, $config, 'App\Modules\DummyModule\Http\Resources\DummyModel'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Insert the given model to storage. |
41
|
|
|
* |
42
|
|
|
* @param InsertDummy $request |
43
|
|
|
* @return \Illuminate\Http\Response |
44
|
|
|
*/ |
45
|
|
|
public function insert(InsertDummy $request) |
46
|
|
|
{ |
47
|
|
|
return new $this->modelResource($this->repo->save($request->all())); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Update the given model to storage. |
52
|
|
|
* |
53
|
|
|
* @param UpdateDummy $request |
54
|
|
|
* @return \Illuminate\Http\Response |
55
|
|
|
*/ |
56
|
|
|
public function update(UpdateDummy $request) |
57
|
|
|
{ |
58
|
|
|
return new $this->modelResource($this->repo->save($request->all())); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.