Completed
Pull Request — develop (#8)
by Abdelrahman
11:18 queued 07:43
created

TestimonialsController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Testimonials\Http\Controllers\Adminarea;
6
7
use Illuminate\Foundation\Http\FormRequest;
8
use Rinvex\Testimonials\Models\Testimonial;
9
use Cortex\Foundation\DataTables\LogsDataTable;
10
use Cortex\Foundation\Http\Controllers\AuthorizedController;
11
use Cortex\Testimonials\DataTables\Adminarea\TestimonialsDataTable;
12
use Cortex\Testimonials\Http\Requests\Adminarea\TestimonialFormRequest;
13
14
class TestimonialsController extends AuthorizedController
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected $resource = 'testimonial';
20
21
    /**
22
     * List all testimonials.
23
     *
24
     * @param \Cortex\Testimonials\DataTables\Adminarea\TestimonialsDataTable $testimonialsDataTable
25
     *
26
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
27
     */
28
    public function index(TestimonialsDataTable $testimonialsDataTable)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $testimonialsDataTable exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
29
    {
30
        return $testimonialsDataTable->with([
31
            'id' => 'adminarea-testimonials-index-table',
32
            'phrase' => trans('cortex/testimonials::common.testimonials'),
33
        ])->render('cortex/foundation::adminarea.pages.datatable');
34
    }
35
36
    /**
37
     * List testimonial logs.
38
     *
39
     * @param \Cortex\Testimonials\Models\Testimonial     $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
40
     * @param \Cortex\Foundation\DataTables\LogsDataTable $logsDataTable
41
     *
42
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\JsonRes...e|\Illuminate\View\View?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
43
     */
44
    public function logs(Testimonial $testimonial, LogsDataTable $logsDataTable)
45
    {
46
        return $logsDataTable->with([
47
            'resource' => $testimonial,
48
            'tabs' => 'adminarea.testimonials.tabs',
49
            'phrase' => trans('cortex/testimonials::common.testimonials'),
50
            'id' => "adminarea-testimonials-{$testimonial->getKey()}-logs-table",
51
        ])->render('cortex/foundation::adminarea.pages.datatable-logs');
52
    }
53
54
    /**
55
     * Create new testimonial.
56
     *
57
     * @param \Cortex\Testimonials\Models\Testimonial $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
58
     *
59
     * @return \Illuminate\View\View
60
     */
61
    public function create(Testimonial $testimonial)
62
    {
63
        return $this->form($testimonial);
64
    }
65
66
    /**
67
     * Edit given testimonial.
68
     *
69
     * @param \Cortex\Testimonials\Models\Testimonial $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
70
     *
71
     * @return \Illuminate\View\View
72
     */
73
    public function edit(Testimonial $testimonial)
74
    {
75
        return $this->form($testimonial);
76
    }
77
78
    /**
79
     * Show testimonial create/edit form.
80
     *
81
     * @param \Cortex\Testimonials\Models\Testimonial $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
82
     *
83
     * @return \Illuminate\View\View
84
     */
85
    protected function form(Testimonial $testimonial)
86
    {
87
        return view('cortex/testimonials::adminarea.pages.testimonial', compact('testimonial'));
88
    }
89
90
    /**
91
     * Store new testimonial.
92
     *
93
     * @param \Cortex\Testimonials\Http\Requests\Adminarea\TestimonialFormRequest $request
94
     * @param \Cortex\Testimonials\Models\Testimonial                             $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
95
     *
96
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
97
     */
98
    public function store(TestimonialFormRequest $request, Testimonial $testimonial)
99
    {
100
        return $this->process($request, $testimonial);
101
    }
102
103
    /**
104
     * Update given testimonial.
105
     *
106
     * @param \Cortex\Testimonials\Http\Requests\Adminarea\TestimonialFormRequest $request
107
     * @param \Cortex\Testimonials\Models\Testimonial                             $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
108
     *
109
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
110
     */
111
    public function update(TestimonialFormRequest $request, Testimonial $testimonial)
112
    {
113
        return $this->process($request, $testimonial);
114
    }
115
116
    /**
117
     * Process stored/updated testimonial.
118
     *
119
     * @param \Illuminate\Foundation\Http\FormRequest $request
120
     * @param \Cortex\Testimonials\Models\Testimonial $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
121
     *
122
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
123
     */
124
    protected function process(FormRequest $request, Testimonial $testimonial)
125
    {
126
        // Prepare required input fields
127
        $data = $request->validated();
128
129
        // Save testimonial
130
        $testimonial->fill($data)->save();
131
132
        return intend([
133
            'url' => route('adminarea.testimonials.index'),
134
            'with' => ['success' => trans('cortex/foundation::messages.resource_saved', ['resource' => 'testimonial', 'id' => $testimonial->getKey()])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 152 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
135
        ]);
136
    }
137
138
    /**
139
     * Destroy given testimonial.
140
     *
141
     * @param \Cortex\Testimonials\Models\Testimonial $testimonial
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $testimonial a bit more specific; maybe use Testimonial.
Loading history...
142
     *
143
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\JsonRes...e\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
144
     */
145
    public function destroy(Testimonial $testimonial)
146
    {
147
        $testimonial->delete();
148
149
        return intend([
150
            'url' => route('adminarea.testimonials.index'),
151
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => 'testimonial', 'id' => $testimonial->getKey()])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 154 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
152
        ]);
153
    }
154
}
155