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

HasResourceActions::destroy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
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
}