Issues (413)

app/Traits/BackendCurd.php (3 issues)

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sheldon
5
 * Date: 18-4-11
6
 * Time: 下午1:12.
7
 */
8
9
namespace Yeelight\Traits;
10
11
use Illuminate\Support\Facades\Input;
12
13
/**
14
 * Trait BackendCurd
15
 *
16
 * @category Yeelight
17
 *
18
 * @package Yeelight\Traits
19
 *
20
 * @author Sheldon Lee <[email protected]>
21
 *
22
 * @license https://opensource.org/licenses/MIT MIT
23
 *
24
 * @link https://www.yeelight.com
25
 */
26
trait BackendCurd
27
{
28
    /**
29
     * Display a listing of the resource.
30
     *
31
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
32
     */
33
    public function index()
34
    {
35
        return $this->repository->all();
36
    }
37
38
    /**
39
     * Display the specified resource.
40
     *
41
     * @param $id
42
     *
43
     * @return mixed
44
     */
45
    public function show($id)
46
    {
47
        return $this->repository->find($id);
48
    }
49
50
    /**
51
     * Remove the specified resource from storage.
52
     *
53
     * @param $id
54
     *
55
     * @return \Illuminate\Http\JsonResponse
56
     */
57
    public function destroy($id)
58
    {
59
        $ids = explode(',', $id);
60
        $deleted = $this->repository->deleteIn($ids);
61
62
        if ($deleted) {
63
            return response()->json([
0 ignored issues
show
The method json() does not exist on Symfony\Component\HttpFoundation\Response. It seems like you code against a sub-type of Symfony\Component\HttpFoundation\Response such as Illuminate\Http\Response or Illuminate\Http\JsonResponse or Illuminate\Http\RedirectResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
            return response()->/** @scrutinizer ignore-call */ json([
Loading history...
64
                'status'  => true,
65
                'message' => trans('backend.delete_succeeded'),
66
            ]);
67
        } else {
68
            return response()->json([
69
                'status'  => false,
70
                'message' => trans('backend.delete_failed'),
71
            ]);
72
        }
73
    }
74
75
    /**
76
     * Get RedirectResponse after store.
77
     *
78
     * @return \Illuminate\Http\RedirectResponse
79
     */
80
    protected function redirectAfterStore()
81
    {
82
        backend_toastr(trans('backend.save_succeeded'));
83
84
        $url = Input::get('_previous_') ?: get_resource(0);
85
86
        return redirect($url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($url) also could return the type Illuminate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
87
    }
88
89
    /**
90
     * Get RedirectResponse after update.
91
     *
92
     * @return \Illuminate\Http\RedirectResponse
93
     */
94
    protected function redirectAfterUpdate()
95
    {
96
        backend_toastr(trans('backend.update_succeeded'));
97
98
        $url = Input::get('_previous_') ?: get_resource(-1);
99
100
        return redirect($url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($url) also could return the type Illuminate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\RedirectResponse.
Loading history...
101
    }
102
}
103