Completed
Push — master ( f1b3fc...e97c85 )
by Nick
02:27
created

GenericController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace EloquentJs\Controllerless;
4
5
use EloquentJs\Model\AcceptsEloquentJsQueries;
6
use Illuminate\Http\Request;
7
use Illuminate\Routing\Controller;
8
9
class GenericController extends Controller
10
{
11
    /**
12
     * @var AcceptsEloquentJsQueries
13
     */
14
    protected $model;
15
16
    /**
17
     * Create a new GenericController instance.
18
     *
19
     * @param AcceptsEloquentJsQueries $model
20
     */
21
    public function __construct(AcceptsEloquentJsQueries $model = null)
22
    {
23
        $this->model = $model;
24
    }
25
26
    /**
27
     * Display a listing of the resource.
28
     *
29
     * @return \Illuminate\Http\Response
30
     */
31
    public function index()
32
    {
33
        return $this->model->eloquentJs()->get();
0 ignored issues
show
Bug introduced by
The method eloquentJs() does not exist on EloquentJs\Model\AcceptsEloquentJsQueries. Did you maybe mean scopeEloquentJs()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
    }
35
36
    /**
37
     * Store a newly created resource in storage.
38
     *
39
     * @param  \Illuminate\Http\Request  $request
40
     * @return Model
41
     */
42
    public function store(Request $request)
43
    {
44
        return $this->model->create($request->all());
0 ignored issues
show
Bug introduced by
The method create() does not seem to exist on object<EloquentJs\Model\AcceptsEloquentJsQueries>.

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...
45
    }
46
47
    /**
48
     * Display the specified resource.
49
     *
50
     * @param  int  $id
51
     * @return \Illuminate\Http\Response
52
     */
53
    public function show($id)
54
    {
55
        return $this->model->eloquentJs()->find($id);
0 ignored issues
show
Bug introduced by
The method eloquentJs() does not exist on EloquentJs\Model\AcceptsEloquentJsQueries. Did you maybe mean scopeEloquentJs()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
    }
57
58
    /**
59
     * Update the specified resource in storage.
60
     *
61
     * @param  \Illuminate\Http\Request  $request
62
     * @param  int  $id
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function update(Request $request, $id)
66
    {
67
        $resource = $this->model->findOrFail($id);
0 ignored issues
show
Bug introduced by
The method findOrFail() does not seem to exist on object<EloquentJs\Model\AcceptsEloquentJsQueries>.

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...
68
69
        $resource->update($request->all());
70
71
        return $resource;
72
    }
73
74
    /**
75
     * Remove the specified resource from storage.
76
     *
77
     * @param  int  $id
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function destroy($id)
81
    {
82
        $resource = $this->model->findOrFail($id);
0 ignored issues
show
Bug introduced by
The method findOrFail() does not seem to exist on object<EloquentJs\Model\AcceptsEloquentJsQueries>.

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...
83
84
        return ['success' => $resource->delete()];
85
    }
86
87
    /**
88
     * Update all resources in storage.
89
     *
90
     * @param  \Illuminate\Http\Request  $request
91
     * @return \Illuminate\Http\Response
92
     */
93
    public function updateAll(Request $request)
94
    {
95
        return [
96
            'updated' => $this->model->newQuery()->eloquentJs()->update($request->all())
0 ignored issues
show
Bug introduced by
The method newQuery() does not seem to exist on object<EloquentJs\Model\AcceptsEloquentJsQueries>.

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...
97
        ];
98
    }
99
100
    /**
101
     * Remove all resources from storage.
102
     *
103
     * @return \Illuminate\Http\Response
104
     */
105
    public function destroyAll()
106
    {
107
        return [
108
            'deleted' => $this->model->newQuery()->eloquentJs()->delete()
0 ignored issues
show
Bug introduced by
The method newQuery() does not seem to exist on object<EloquentJs\Model\AcceptsEloquentJsQueries>.

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...
109
        ];
110
    }
111
}
112