Completed
Push — master ( 81d5c5...b85859 )
by Arjay
01:15
created

DataTablesEditor::forceDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Yajra\DataTables;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\QueryException;
9
use Illuminate\Support\Facades\Storage;
10
use Illuminate\Contracts\Validation\Validator;
11
use Illuminate\Validation\ValidationException;
12
use Illuminate\Foundation\Validation\ValidatesRequests;
13
14
abstract class DataTablesEditor
15
{
16
    use ValidatesRequests;
17
18
    /**
19
     * Allowed dataTables editor actions.
20
     *
21
     * @var array
22
     */
23
    protected $actions = ['create', 'edit', 'remove', 'upload', 'forceDelete'];
24
25
    /**
26
     * @var \Illuminate\Database\Eloquent\Model
27
     */
28
    protected $model = null;
29
30
    /**
31
     * Indicates if all mass assignment is enabled on model.
32
     *
33
     * @var bool
34
     */
35
    protected $unguarded = false;
36
37
    /**
38
     * Upload directory relative to storage path.
39
     *
40
     * @var string
41
     */
42
    protected $uploadDir = 'editor';
43
44
    /**
45
     * Flag to force delete a model.
46
     *
47
     * @var bool
48
     */
49
    protected $forceDeleting = false;
50
51
    /**
52
     * Filesystem disk config to use for upload.
53
     *
54
     * @var string
55
     */
56
    protected $disk = 'public';
57
58
    /**
59
     * Process dataTables editor action request.
60
     *
61
     * @param Request $request
62
     * @return JsonResponse|mixed
63
     * @throws DataTablesEditorException
64
     */
65
    public function process(Request $request)
66
    {
67
        $action = $request->get('action');
68
69
        if (! in_array($action, $this->actions)) {
70
            throw new DataTablesEditorException('Requested action not supported!');
71
        }
72
73
        return $this->{$action}($request);
74
    }
75
76
    /**
77
     * Process create action request.
78
     *
79
     * @param Request $request
80
     * @return JsonResponse
81
     */
82 View Code Duplication
    public function create(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        $instance   = $this->resolveModel();
85
        $connection = $instance->getConnection();
86
        $affected   = [];
87
        $errors     = [];
88
89
        $connection->beginTransaction();
90
        foreach ($request->get('data') as $data) {
91
            $validator = $this->getValidationFactory()
92
                              ->make($data, $this->createRules(), $this->messages() + $this->createMessages(), $this->attributes());
0 ignored issues
show
Deprecated Code introduced by
The method Yajra\DataTables\DataTab...ditor::createMessages() has been deprecated with message: deprecated since v1.12.0, please use messages() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
93
            if ($validator->fails()) {
94
                foreach ($this->formatErrors($validator) as $error) {
95
                    $errors[] = $error;
96
                }
97
98
                continue;
99
            }
100
101
            if (method_exists($this, 'creating')) {
102
                $data = $this->creating($instance, $data);
0 ignored issues
show
Bug introduced by
The method creating() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
103
            }
104
105
            if (method_exists($this, 'saving')) {
106
                $data = $this->saving($instance, $data);
0 ignored issues
show
Bug introduced by
The method saving() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
107
            }
108
109
            $instance->fill($data)->save();
110
111
            if (method_exists($this, 'created')) {
112
                $instance = $this->created($instance, $data);
0 ignored issues
show
Bug introduced by
The method created() does not exist on Yajra\DataTables\DataTablesEditor. Did you maybe mean create()?

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...
113
            }
114
115
            if (method_exists($this, 'saved')) {
116
                $instance = $this->saved($instance, $data);
0 ignored issues
show
Bug introduced by
The method saved() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
117
            }
118
119
            $instance->setAttribute('DT_RowId', $instance->getKey());
120
            $affected[] = $instance;
121
        }
122
123
        if (! $errors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
124
            $connection->commit();
125
        } else {
126
            $connection->rollBack();
127
        }
128
129
        return $this->toJson($affected, $errors);
130
    }
131
132
    /**
133
     * Resolve model to used.
134
     *
135
     * @return Model|\Illuminate\Database\Eloquent\SoftDeletes
136
     */
137
    protected function resolveModel()
138
    {
139
        if (! $this->model instanceof Model) {
140
            $this->model = new $this->model;
141
        }
142
143
        $this->model->unguard($this->unguarded);
144
145
        return $this->model;
146
    }
147
148
    /**
149
     * Get create action validation rules.
150
     *
151
     * @return array
152
     */
153
    abstract public function createRules();
154
155
    /**
156
     * Get create validation messages.
157
     *
158
     * @deprecated deprecated since v1.12.0, please use messages() instead.
159
     * @return array
160
     */
161
    protected function createMessages()
162
    {
163
        return [];
164
    }
165
166
    /**
167
     * Get custom attributes for validator errors.
168
     *
169
     * @return array
170
     */
171
    public function attributes()
172
    {
173
        return [];
174
    }
175
176
    /**
177
     * @param Validator $validator
178
     * @return array
179
     */
180
    protected function formatErrors(Validator $validator)
181
    {
182
        $errors = [];
183
184
        collect($validator->errors())->each(function ($error, $key) use (&$errors) {
185
            $errors[] = [
186
                'name'   => $key,
187
                'status' => $error[0],
188
            ];
189
        });
190
191
        return $errors;
192
    }
193
194
    /**
195
     * Display success data in dataTables editor format.
196
     *
197
     * @param array $data
198
     * @param array $errors
199
     * @return JsonResponse
200
     */
201
    protected function toJson(array $data, array $errors = [])
202
    {
203
        $response = ['data' => $data];
204
        if ($errors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
205
            $response['fieldErrors'] = $errors;
206
        }
207
208
        return new JsonResponse($response, 200);
209
    }
210
211
    /**
212
     * Process edit action request.
213
     *
214
     * @param Request $request
215
     * @return JsonResponse
216
     */
217 View Code Duplication
    public function edit(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
218
    {
219
        $connection = $this->getBuilder()->getConnection();
220
        $affected   = [];
221
        $errors     = [];
222
223
        $connection->beginTransaction();
224
        foreach ($request->get('data') as $key => $data) {
225
            $model     = $this->getBuilder()->findOrFail($key);
226
            $validator = $this->getValidationFactory()
227
                              ->make($data, $this->editRules($model), $this->messages() + $this->editMessages(), $this->attributes());
0 ignored issues
show
Documentation introduced by
$model is of type object|null, but the function expects a object<Illuminate\Database\Eloquent\Model>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Yajra\DataTables\DataTablesEditor::editMessages() has been deprecated with message: deprecated since v1.12.0, please use messages() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
228
            if ($validator->fails()) {
229
                foreach ($this->formatErrors($validator) as $error) {
230
                    $errors[] = $error;
231
                }
232
233
                continue;
234
            }
235
236
            if (method_exists($this, 'updating')) {
237
                $data = $this->updating($model, $data);
0 ignored issues
show
Bug introduced by
The method updating() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
238
            }
239
240
            if (method_exists($this, 'saving')) {
241
                $data = $this->saving($model, $data);
0 ignored issues
show
Bug introduced by
The method saving() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
242
            }
243
244
            $model->fill($data)->save();
245
246
            if (method_exists($this, 'updated')) {
247
                $model = $this->updated($model, $data);
0 ignored issues
show
Bug introduced by
The method updated() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
248
            }
249
250
            if (method_exists($this, 'saved')) {
251
                $model = $this->saved($model, $data);
0 ignored issues
show
Bug introduced by
The method saved() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
252
            }
253
254
            $model->setAttribute('DT_RowId', $model->getKey());
255
            $affected[] = $model;
256
        }
257
258
        if (! $errors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
259
            $connection->commit();
260
        } else {
261
            $connection->rollBack();
262
        }
263
264
        return $this->toJson($affected, $errors);
265
    }
266
267
    /**
268
     * Get elqouent builder of the model.
269
     *
270
     * @return \Illuminate\Database\Eloquent\Builder
271
     */
272
    protected function getBuilder()
273
    {
274
        $model = $this->resolveModel();
275
276
        if (in_array(\Illuminate\Database\Eloquent\SoftDeletes::class, class_uses($model))) {
277
            return $model->newQuery()->withTrashed();
278
        }
279
280
        return $model->newQuery();
281
    }
282
283
    /**
284
     * Get edit action validation rules.
285
     *
286
     * @param Model $model
287
     * @return array
288
     */
289
    abstract public function editRules(Model $model);
290
291
    /**
292
     * Get edit validation messages.
293
     *
294
     * @deprecated deprecated since v1.12.0, please use messages() instead.
295
     * @return array
296
     */
297
    protected function editMessages()
298
    {
299
        return [];
300
    }
301
302
    /**
303
     * Process force delete action request.
304
     *
305
     * @param \Illuminate\Http\Request $request
306
     * @return \Illuminate\Http\JsonResponse
307
     */
308
    public function forceDelete(Request $request)
309
    {
310
        $this->forceDeleting = true;
311
312
        return $this->remove($request);
313
    }
314
315
    /**
316
     * Process remove action request.
317
     *
318
     * @param Request $request
319
     * @return JsonResponse
320
     */
321
    public function remove(Request $request)
322
    {
323
        $connection = $this->getBuilder()->getConnection();
324
        $affected   = [];
325
        $errors     = [];
326
327
        $connection->beginTransaction();
328
        foreach ($request->get('data') as $key => $data) {
329
            $model     = $this->getBuilder()->findOrFail($key);
330
            $validator = $this->getValidationFactory()
331
                              ->make($data, $this->removeRules($model), $this->messages() + $this->removeMessages(), $this->attributes());
0 ignored issues
show
Documentation introduced by
$model is of type object|null, but the function expects a object<Illuminate\Database\Eloquent\Model>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Yajra\DataTables\DataTab...ditor::removeMessages() has been deprecated with message: deprecated since v1.12.0, please use messages() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
332
            if ($validator->fails()) {
333
                foreach ($this->formatErrors($validator) as $error) {
334
                    $errors[] = $error['status'];
335
                }
336
337
                continue;
338
            }
339
340
            try {
341
                $deleted = clone $model;
342
                if (method_exists($this, 'deleting')) {
343
                    $this->deleting($model, $data);
0 ignored issues
show
Bug introduced by
The method deleting() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
344
                }
345
346
                $this->forceDeleting ? $model->forceDelete() : $model->delete();
347
348
                if (method_exists($this, 'deleted')) {
349
                    $this->deleted($deleted, $data);
0 ignored issues
show
Bug introduced by
The method deleted() does not seem to exist on object<Yajra\DataTables\DataTablesEditor>.

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...
350
                }
351
            } catch (QueryException $exception) {
352
                $error = config('app.debug')
353
                    ? $exception->errorInfo[2]
354
                    : $this->removeExceptionMessage($exception, $model);
0 ignored issues
show
Documentation introduced by
$model is of type object|null, but the function expects a object<Illuminate\Database\Eloquent\Model>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
355
356
                $errors[] = $error;
357
            }
358
359
            $affected[] = $deleted;
360
        }
361
362
        if (! $errors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
363
            $connection->commit();
364
        } else {
365
            $connection->rollBack();
366
        }
367
368
        $response = ['data' => $affected];
369
        if ($errors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
370
            $response['error'] = implode("\n", $errors);
371
        }
372
373
        return new JsonResponse($response, 200);
374
    }
375
376
    /**
377
     * Get remove action validation rules.
378
     *
379
     * @param Model $model
380
     * @return array
381
     */
382
    abstract public function removeRules(Model $model);
383
384
    /**
385
     * Get remove validation messages.
386
     *
387
     * @deprecated deprecated since v1.12.0, please use messages() instead.
388
     * @return array
389
     */
390
    protected function removeMessages()
391
    {
392
        return [];
393
    }
394
395
    /**
396
     * Get remove query exception message.
397
     *
398
     * @param QueryException $exception
399
     * @param Model $model
400
     * @return string
401
     */
402
    protected function removeExceptionMessage(QueryException $exception, Model $model)
0 ignored issues
show
Unused Code introduced by
The parameter $exception is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
403
    {
404
        return "Record {$model->getKey()} is protected and cannot be deleted!";
405
    }
406
407
    /**
408
     * Get dataTables model.
409
     *
410
     * @return Model
411
     */
412
    public function getModel()
413
    {
414
        return $this->model;
415
    }
416
417
    /**
418
     * Set the dataTables model on runtime.
419
     *
420
     * @param Model|string $model
421
     * @return DataTablesEditor
422
     */
423
    public function setModel($model)
424
    {
425
        $this->model = $model;
0 ignored issues
show
Documentation Bug introduced by
It seems like $model can also be of type string. However, the property $model is declared as type object<Illuminate\Database\Eloquent\Model>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
426
427
        return $this;
428
    }
429
430
    /**
431
     * Set model unguard state.
432
     *
433
     * @param bool $state
434
     * @return $this
435
     */
436
    public function unguard($state = true)
437
    {
438
        $this->unguarded = $state;
439
440
        return $this;
441
    }
442
443
    /**
444
     * Handle uploading of file.
445
     *
446
     * @param \Illuminate\Http\Request $request
447
     * @return \Illuminate\Http\JsonResponse
448
     */
449
    public function upload(Request $request)
450
    {
451
        $field   = $request->input('uploadField');
452
        $storage = Storage::disk($this->disk);
453
454
        try {
455
            $rules      = $this->uploadRules();
456
            $fieldRules = ['upload' => data_get($rules, $field, [])];
0 ignored issues
show
Bug introduced by
It seems like $field defined by $request->input('uploadField') on line 451 can also be of type null; however, data_get() does only seem to accept string|array|integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
457
458
            $this->validate($request, $fieldRules, $this->messages(), $this->attributes());
459
460
            $id = $storage->putFile($this->uploadDir, $request->file('upload'));
461
462
            if (method_exists($this, 'uploaded')) {
463
                $id = $this->uploaded($id);
0 ignored issues
show
Bug introduced by
The method uploaded() does not exist on Yajra\DataTables\DataTablesEditor. Did you maybe mean upload()?

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...
464
            }
465
466
            return response()->json([
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
467
                'data'   => [],
468
                'files'   => [
469
                    'files' => [
470
                        $id => [
471
                            'filename'  => $id,
472
                            'size'      => $request->file('upload')->getSize(),
473
                            'directory' => $this->uploadDir,
474
                            'disk'      => $this->disk,
475
                            'url'       => $storage->url($id),
476
                        ]
477
                    ]
478
                ],
479
                'upload' => [
480
                    'id' => $id,
481
                ],
482
            ]);
483
        } catch (ValidationException $exception) {
484
            return response()->json([
485
                'data'        => [],
486
                'fieldErrors' => [
487
                    [
488
                        'name'   => $field,
489
                        'status' => str_replace('upload', $field, $exception->errors()['upload'][0]),
490
                    ],
491
                ],
492
            ]);
493
        }
494
    }
495
496
    /**
497
     * Upload validation rules.
498
     *
499
     * @return array
500
     */
501
    public function uploadRules()
502
    {
503
        return [];
504
    }
505
506
    /**
507
     * Get validation messages.
508
     *
509
     * @return array
510
     */
511
    protected function messages()
512
    {
513
        return [];
514
    }
515
516
    /**
517
     * Display dataTables editor validation errors.
518
     *
519
     * @param Validator $validator
520
     * @return JsonResponse
521
     */
522
    protected function displayValidationErrors(Validator $validator)
523
    {
524
        $errors = $this->formatErrors($validator);
525
526
        return new JsonResponse([
527
            'data'        => [],
528
            'fieldErrors' => $errors,
529
        ]);
530
    }
531
}
532