Completed
Push — master ( ce62e6...a2dd34 )
by Song
03:32
created

HasResourceActions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 4 1
A store() 0 4 1
A destroy() 0 16 2
1
<?php
2
3
namespace Encore\Admin\Controllers;
4
5
trait HasResourceActions
6
{
7
    /**
8
     * Update the specified resource in storage.
9
     *
10
     * @param  int  $id
11
     * @return \Illuminate\Http\Response
12
     */
13
    public function update($id)
14
    {
15
        return $this->resource->form()->update($id);
0 ignored issues
show
Bug introduced by
The property resource does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
    }
17
18
    /**
19
     * Store a newly created resource in storage.
20
     *
21
     * @return mixed
22
     */
23
    public function store()
24
    {
25
        return $this->resource->form()->store();
26
    }
27
28
    /**
29
     * Remove the specified resource from storage.
30
     *
31
     * @param  int  $id
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function destroy($id)
35
    {
36
        if ($this->resource->form()->destroy($id)) {
37
            $data = [
38
                'status'  => true,
39
                'message' => trans('admin.delete_succeeded'),
40
            ];
41
        } else {
42
            $data = [
43
                'status'  => false,
44
                'message' => trans('admin.delete_failed'),
45
            ];
46
        }
47
48
        return response()->json($data);
49
    }
50
}