Completed
Push — master ( bcf5c2...bd2c35 )
by Arjay
01:13
created

DataTablesEditor::restore()   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 = [
24
        'create',
25
        'edit',
26
        'remove',
27
        'upload',
28
        'forceDelete',
29
        'restore',
30
    ];
31
32
    /**
33
     * @var \Illuminate\Database\Eloquent\Model
34
     */
35
    protected $model = null;
36
37
    /**
38
     * Indicates if all mass assignment is enabled on model.
39
     *
40
     * @var bool
41
     */
42
    protected $unguarded = false;
43
44
    /**
45
     * Upload directory relative to storage path.
46
     *
47
     * @var string
48
     */
49
    protected $uploadDir = 'editor';
50
51
    /**
52
     * Flag to force delete a model.
53
     *
54
     * @var bool
55
     */
56
    protected $forceDeleting = false;
57
58
    /**
59
     * Flag to restore a model from deleted state.
60
     *
61
     * @var bool
62
     */
63
    protected $restoring = false;
64
65
    /**
66
     * Filesystem disk config to use for upload.
67
     *
68
     * @var string
69
     */
70
    protected $disk = 'public';
71
72
    /**
73
     * Process dataTables editor action request.
74
     *
75
     * @param Request $request
76
     * @return JsonResponse|mixed
77
     * @throws DataTablesEditorException
78
     */
79
    public function process(Request $request)
80
    {
81
        $action = $request->get('action');
82
83
        if (! in_array($action, $this->actions)) {
84
            throw new DataTablesEditorException('Requested action not supported!');
85
        }
86
87
        return $this->{$action}($request);
88
    }
89
90
    /**
91
     * Process create action request.
92
     *
93
     * @param Request $request
94
     * @return JsonResponse
95
     */
96
    public function create(Request $request)
97
    {
98
        $model      = $this->resolveModel();
99
        $connection = $model->getConnection();
100
        $affected   = [];
101
        $errors     = [];
102
103
        $connection->beginTransaction();
104
        foreach ($request->get('data') as $data) {
105
            $instance  = $model->newInstance();
106
            $validator = $this->getValidationFactory()
107
                              ->make(
108
                                  $data,
109
                                  $this->createRules(), $this->messages() + $this->createMessages(),
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...
110
                                  $this->attributes()
111
                              );
112
            if ($validator->fails()) {
113
                foreach ($this->formatErrors($validator) as $error) {
114
                    $errors[] = $error;
115
                }
116
117
                continue;
118
            }
119
120
            if (method_exists($this, 'creating')) {
121
                $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...
122
            }
123
124
            if (method_exists($this, 'saving')) {
125
                $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...
126
            }
127
128
            $instance->fill($data)->save();
129
130
            if (method_exists($this, 'created')) {
131
                $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...
132
            }
133
134
            if (method_exists($this, 'saved')) {
135
                $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...
136
            }
137
138
            $instance->setAttribute('DT_RowId', $instance->getKey());
139
            $affected[] = $instance;
140
        }
141
142
        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...
143
            $connection->commit();
144
        } else {
145
            $connection->rollBack();
146
        }
147
148
        return $this->toJson($affected, $errors);
149
    }
150
151
    /**
152
     * Resolve model to used.
153
     *
154
     * @return Model|\Illuminate\Database\Eloquent\SoftDeletes
155
     */
156
    protected function resolveModel()
157
    {
158
        if (! $this->model instanceof Model) {
159
            $this->model = new $this->model;
160
        }
161
162
        $this->model->unguard($this->unguarded);
163
164
        return $this->model;
165
    }
166
167
    /**
168
     * Get create action validation rules.
169
     *
170
     * @return array
171
     */
172
    abstract public function createRules();
173
174
    /**
175
     * Get validation messages.
176
     *
177
     * @return array
178
     */
179
    protected function messages()
180
    {
181
        return [];
182
    }
183
184
    /**
185
     * Get create validation messages.
186
     *
187
     * @return array
188
     * @deprecated deprecated since v1.12.0, please use messages() instead.
189
     */
190
    protected function createMessages()
191
    {
192
        return [];
193
    }
194
195
    /**
196
     * Get custom attributes for validator errors.
197
     *
198
     * @return array
199
     */
200
    public function attributes()
201
    {
202
        return [];
203
    }
204
205
    /**
206
     * @param Validator $validator
207
     * @return array
208
     */
209
    protected function formatErrors(Validator $validator)
210
    {
211
        $errors = [];
212
213
        collect($validator->errors())->each(function ($error, $key) use (&$errors) {
214
            $errors[] = [
215
                'name'   => $key,
216
                'status' => $error[0],
217
            ];
218
        });
219
220
        return $errors;
221
    }
222
223
    /**
224
     * Display success data in dataTables editor format.
225
     *
226
     * @param array $data
227
     * @param array $errors
228
     * @return JsonResponse
229
     */
230
    protected function toJson(array $data, array $errors = [])
231
    {
232
        $response = ['data' => $data];
233
        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...
234
            $response['fieldErrors'] = $errors;
235
        }
236
237
        return new JsonResponse($response, 200);
238
    }
239
240
    /**
241
     * Process restore action request.
242
     *
243
     * @param \Illuminate\Http\Request $request
244
     * @return \Illuminate\Http\JsonResponse
245
     */
246
    public function restore(Request $request)
247
    {
248
        $this->restoring = true;
249
250
        return $this->edit($request);
251
    }
252
253
    /**
254
     * Process edit action request.
255
     *
256
     * @param Request $request
257
     * @return JsonResponse
258
     */
259
    public function edit(Request $request)
260
    {
261
        $connection = $this->getBuilder()->getConnection();
262
        $affected   = [];
263
        $errors     = [];
264
265
        $connection->beginTransaction();
266
        foreach ($request->get('data') as $key => $data) {
267
            $model     = $this->getBuilder()->findOrFail($key);
268
            $validator = $this->getValidationFactory()
269
                              ->make(
270
                                  $data,
271
                                  $this->editRules($model), $this->messages() + $this->editMessages(),
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...
272
                                  $this->attributes()
273
                              );
274
            if ($validator->fails()) {
275
                foreach ($this->formatErrors($validator) as $error) {
276
                    $errors[] = $error;
277
                }
278
279
                continue;
280
            }
281
282
            if (method_exists($this, 'updating')) {
283
                $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...
284
            }
285
286
            if (method_exists($this, 'saving')) {
287
                $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...
288
            }
289
290
            $this->restoring ? $model->restore() : $model->fill($data)->save();
291
292
            if (method_exists($this, 'updated')) {
293
                $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...
294
            }
295
296
            if (method_exists($this, 'saved')) {
297
                $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...
298
            }
299
300
            $model->setAttribute('DT_RowId', $model->getKey());
301
            $affected[] = $model;
302
        }
303
304
        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...
305
            $connection->commit();
306
        } else {
307
            $connection->rollBack();
308
        }
309
310
        return $this->toJson($affected, $errors);
311
    }
312
313
    /**
314
     * Get elqouent builder of the model.
315
     *
316
     * @return \Illuminate\Database\Eloquent\Builder
317
     */
318
    protected function getBuilder()
319
    {
320
        $model = $this->resolveModel();
321
322
        if (in_array(\Illuminate\Database\Eloquent\SoftDeletes::class, class_uses($model))) {
323
            return $model->newQuery()->withTrashed();
324
        }
325
326
        return $model->newQuery();
327
    }
328
329
    /**
330
     * Get edit action validation rules.
331
     *
332
     * @param Model $model
333
     * @return array
334
     */
335
    abstract public function editRules(Model $model);
336
337
    /**
338
     * Get edit validation messages.
339
     *
340
     * @return array
341
     * @deprecated deprecated since v1.12.0, please use messages() instead.
342
     */
343
    protected function editMessages()
344
    {
345
        return [];
346
    }
347
348
    /**
349
     * Process force delete action request.
350
     *
351
     * @param \Illuminate\Http\Request $request
352
     * @return \Illuminate\Http\JsonResponse
353
     */
354
    public function forceDelete(Request $request)
355
    {
356
        $this->forceDeleting = true;
357
358
        return $this->remove($request);
359
    }
360
361
    /**
362
     * Process remove action request.
363
     *
364
     * @param Request $request
365
     * @return JsonResponse
366
     */
367
    public function remove(Request $request)
368
    {
369
        $connection = $this->getBuilder()->getConnection();
370
        $affected   = [];
371
        $errors     = [];
372
373
        $connection->beginTransaction();
374
        foreach ($request->get('data') as $key => $data) {
375
            $model     = $this->getBuilder()->findOrFail($key);
376
            $validator = $this->getValidationFactory()
377
                              ->make(
378
                                  $data,
379
                                  $this->removeRules($model), $this->messages() + $this->removeMessages(),
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...
380
                                  $this->attributes()
381
                              );
382
            if ($validator->fails()) {
383
                foreach ($this->formatErrors($validator) as $error) {
384
                    $errors[] = $error['status'];
385
                }
386
387
                continue;
388
            }
389
390
            try {
391
                $deleted = clone $model;
392
                if (method_exists($this, 'deleting')) {
393
                    $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...
394
                }
395
396
                $this->forceDeleting ? $model->forceDelete() : $model->delete();
397
398
                if (method_exists($this, 'deleted')) {
399
                    $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...
400
                }
401
            } catch (QueryException $exception) {
402
                $error = config('app.debug')
403
                    ? $exception->errorInfo[2]
404
                    : $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...
405
406
                $errors[] = $error;
407
            }
408
409
            $affected[] = $deleted;
410
        }
411
412
        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...
413
            $connection->commit();
414
        } else {
415
            $connection->rollBack();
416
        }
417
418
        $response = ['data' => $affected];
419
        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...
420
            $response['error'] = implode("\n", $errors);
421
        }
422
423
        return new JsonResponse($response, 200);
424
    }
425
426
    /**
427
     * Get remove action validation rules.
428
     *
429
     * @param Model $model
430
     * @return array
431
     */
432
    abstract public function removeRules(Model $model);
433
434
    /**
435
     * Get remove validation messages.
436
     *
437
     * @return array
438
     * @deprecated deprecated since v1.12.0, please use messages() instead.
439
     */
440
    protected function removeMessages()
441
    {
442
        return [];
443
    }
444
445
    /**
446
     * Get remove query exception message.
447
     *
448
     * @param QueryException $exception
449
     * @param Model $model
450
     * @return string
451
     */
452
    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...
453
    {
454
        return "Record {$model->getKey()} is protected and cannot be deleted!";
455
    }
456
457
    /**
458
     * Get dataTables model.
459
     *
460
     * @return Model
461
     */
462
    public function getModel()
463
    {
464
        return $this->model;
465
    }
466
467
    /**
468
     * Set the dataTables model on runtime.
469
     *
470
     * @param Model|string $model
471
     * @return DataTablesEditor
472
     */
473
    public function setModel($model)
474
    {
475
        $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...
476
477
        return $this;
478
    }
479
480
    /**
481
     * Set model unguard state.
482
     *
483
     * @param bool $state
484
     * @return $this
485
     */
486
    public function unguard($state = true)
487
    {
488
        $this->unguarded = $state;
489
490
        return $this;
491
    }
492
493
    /**
494
     * Handle uploading of file.
495
     *
496
     * @param \Illuminate\Http\Request $request
497
     * @return \Illuminate\Http\JsonResponse
498
     */
499
    public function upload(Request $request)
500
    {
501
        $field   = $request->input('uploadField');
502
        $storage = Storage::disk($this->disk);
503
504
        try {
505
            $rules      = $this->uploadRules();
506
            $fieldRules = ['upload' => data_get($rules, $field, [])];
0 ignored issues
show
Bug introduced by
It seems like $field defined by $request->input('uploadField') on line 501 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...
507
508
            $this->validate($request, $fieldRules, $this->messages(), $this->attributes());
509
510
            $id = $storage->putFile($this->uploadDir, $request->file('upload'));
511
512
            if (method_exists($this, 'uploaded')) {
513
                $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...
514
            }
515
516
            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...
517
                'data'   => [],
518
                'files'  => [
519
                    'files' => [
520
                        $id => [
521
                            'filename'  => $id,
522
                            'size'      => $request->file('upload')->getSize(),
523
                            'directory' => $this->uploadDir,
524
                            'disk'      => $this->disk,
525
                            'url'       => $storage->url($id),
526
                        ],
527
                    ],
528
                ],
529
                'upload' => [
530
                    'id' => $id,
531
                ],
532
            ]);
533
        } catch (ValidationException $exception) {
534
            return response()->json([
535
                'data'        => [],
536
                'fieldErrors' => [
537
                    [
538
                        'name'   => $field,
539
                        'status' => str_replace('upload', $field, $exception->errors()['upload'][0]),
540
                    ],
541
                ],
542
            ]);
543
        }
544
    }
545
546
    /**
547
     * Upload validation rules.
548
     *
549
     * @return array
550
     */
551
    public function uploadRules()
552
    {
553
        return [];
554
    }
555
556
    /**
557
     * Display dataTables editor validation errors.
558
     *
559
     * @param Validator $validator
560
     * @return JsonResponse
561
     */
562
    protected function displayValidationErrors(Validator $validator)
563
    {
564
        $errors = $this->formatErrors($validator);
565
566
        return new JsonResponse([
567
            'data'        => [],
568
            'fieldErrors' => $errors,
569
        ]);
570
    }
571
}
572