@@ -96,7 +96,6 @@ abstract class DataTablesEditor
96
96
/**
97
97
* Process dataTables editor action request.
98
98
*
99
- * @param Request $request
100
99
* @return JsonResponse|mixed
101
100
*
102
101
* @throws DataTablesEditorException
@@ -113,7 +112,7 @@ public function process(Request $request)
113
112
return $ this ->{$ this ->action }($ request );
114
113
} catch (Exception $ exception ) {
115
114
$ error = config ('app.debug ' )
116
- ? '<strong>Server Error:</strong> ' . $ exception ->getMessage ()
115
+ ? '<strong>Server Error:</strong> ' . $ exception ->getMessage ()
117
116
: $ this ->getUseFriendlyErrorMessage ();
118
117
119
118
app ('log ' )->error ($ exception );
@@ -133,8 +132,6 @@ protected function getUseFriendlyErrorMessage()
133
132
/**
134
133
* Display success data in dataTables editor format.
135
134
*
136
- * @param array $data
137
- * @param array $errors
138
135
* @param string $error
139
136
* @return JsonResponse
140
137
*/
@@ -144,16 +141,16 @@ protected function toJson(array $data, array $errors = [], $error = '')
144
141
145
142
$ response = [
146
143
'action ' => $ this ->action ,
147
- 'data ' => $ data ,
144
+ 'data ' => $ data ,
148
145
];
149
146
150
147
if ($ error ) {
151
- $ code = 422 ;
148
+ $ code = 422 ;
152
149
$ response ['error ' ] = $ error ;
153
150
}
154
151
155
152
if ($ errors ) {
156
- $ code = 422 ;
153
+ $ code = 422 ;
157
154
$ response ['fieldErrors ' ] = $ errors ;
158
155
}
159
156
@@ -163,29 +160,28 @@ protected function toJson(array $data, array $errors = [], $error = '')
163
160
/**
164
161
* Process create action request.
165
162
*
166
- * @param Request $request
167
163
* @return JsonResponse
168
164
*
169
165
* @throws \Exception
170
166
*/
171
167
public function create (Request $ request )
172
168
{
173
- $ model = $ this ->resolveModel ();
169
+ $ model = $ this ->resolveModel ();
174
170
$ connection = $ model ->getConnection ();
175
- $ affected = [];
176
- $ errors = [];
171
+ $ affected = [];
172
+ $ errors = [];
177
173
178
174
$ connection ->beginTransaction ();
179
175
foreach ($ request ->get ('data ' ) as $ data ) {
180
176
$ this ->currentData = $ data ;
181
177
182
- $ instance = $ model ->newInstance ();
178
+ $ instance = $ model ->newInstance ();
183
179
$ validator = $ this ->getValidationFactory ()
184
- ->make (
185
- $ data ,
186
- $ this ->createRules (), $ this ->messages () + $ this ->createMessages (),
187
- $ this ->attributes ()
188
- );
180
+ ->make (
181
+ $ data ,
182
+ $ this ->createRules (), $ this ->messages () + $ this ->createMessages (),
183
+ $ this ->attributes ()
184
+ );
189
185
if ($ validator ->fails ()) {
190
186
foreach ($ this ->formatErrors ($ validator ) as $ error ) {
191
187
$ errors [] = $ error ;
@@ -284,7 +280,6 @@ public function attributes()
284
280
}
285
281
286
282
/**
287
- * @param Validator $validator
288
283
* @return array
289
284
*/
290
285
protected function formatErrors (Validator $ validator )
@@ -293,7 +288,7 @@ protected function formatErrors(Validator $validator)
293
288
294
289
collect ($ validator ->errors ())->each (function ($ error , $ key ) use (&$ errors ) {
295
290
$ errors [] = [
296
- 'name ' => $ key ,
291
+ 'name ' => $ key ,
297
292
'status ' => $ error [0 ],
298
293
];
299
294
});
@@ -304,7 +299,6 @@ protected function formatErrors(Validator $validator)
304
299
/**
305
300
* Process restore action request.
306
301
*
307
- * @param \Illuminate\Http\Request $request
308
302
* @return \Illuminate\Http\JsonResponse
309
303
*/
310
304
public function restore (Request $ request )
@@ -317,26 +311,25 @@ public function restore(Request $request)
317
311
/**
318
312
* Process edit action request.
319
313
*
320
- * @param Request $request
321
314
* @return JsonResponse
322
315
*/
323
316
public function edit (Request $ request )
324
317
{
325
318
$ connection = $ this ->getBuilder ()->getConnection ();
326
- $ affected = [];
327
- $ errors = [];
319
+ $ affected = [];
320
+ $ errors = [];
328
321
329
322
$ connection ->beginTransaction ();
330
323
foreach ($ request ->get ('data ' ) as $ key => $ data ) {
331
324
$ this ->currentData = $ data ;
332
325
333
- $ model = $ this ->getBuilder ()->findOrFail ($ key );
326
+ $ model = $ this ->getBuilder ()->findOrFail ($ key );
334
327
$ validator = $ this ->getValidationFactory ()
335
- ->make (
336
- $ data ,
337
- $ this ->editRules ($ model ), $ this ->messages () + $ this ->editMessages (),
338
- $ this ->attributes ()
339
- );
328
+ ->make (
329
+ $ data ,
330
+ $ this ->editRules ($ model ), $ this ->messages () + $ this ->editMessages (),
331
+ $ this ->attributes ()
332
+ );
340
333
if ($ validator ->fails ()) {
341
334
foreach ($ this ->formatErrors ($ validator ) as $ error ) {
342
335
$ errors [] = $ error ;
@@ -395,7 +388,6 @@ protected function getBuilder()
395
388
/**
396
389
* Get edit action validation rules.
397
390
*
398
- * @param Model $model
399
391
* @return array
400
392
*/
401
393
public function editRules (Model $ model )
@@ -418,7 +410,6 @@ protected function editMessages()
418
410
/**
419
411
* Process force delete action request.
420
412
*
421
- * @param \Illuminate\Http\Request $request
422
413
* @return \Illuminate\Http\JsonResponse
423
414
*
424
415
* @throws \Exception
@@ -433,28 +424,27 @@ public function forceDelete(Request $request)
433
424
/**
434
425
* Process remove action request.
435
426
*
436
- * @param Request $request
437
427
* @return JsonResponse
438
428
*
439
429
* @throws \Exception
440
430
*/
441
431
public function remove (Request $ request )
442
432
{
443
433
$ connection = $ this ->getBuilder ()->getConnection ();
444
- $ affected = [];
445
- $ errors = [];
434
+ $ affected = [];
435
+ $ errors = [];
446
436
447
437
$ connection ->beginTransaction ();
448
438
foreach ($ request ->get ('data ' ) as $ key => $ data ) {
449
439
$ this ->currentData = $ data ;
450
440
451
- $ model = $ this ->getBuilder ()->findOrFail ($ key );
441
+ $ model = $ this ->getBuilder ()->findOrFail ($ key );
452
442
$ validator = $ this ->getValidationFactory ()
453
- ->make (
454
- $ data ,
455
- $ this ->removeRules ($ model ), $ this ->messages () + $ this ->removeMessages (),
456
- $ this ->attributes ()
457
- );
443
+ ->make (
444
+ $ data ,
445
+ $ this ->removeRules ($ model ), $ this ->messages () + $ this ->removeMessages (),
446
+ $ this ->attributes ()
447
+ );
458
448
if ($ validator ->fails ()) {
459
449
foreach ($ this ->formatErrors ($ validator ) as $ error ) {
460
450
$ errors [] = $ error ['status ' ];
@@ -502,7 +492,6 @@ public function remove(Request $request)
502
492
/**
503
493
* Get remove action validation rules.
504
494
*
505
- * @param Model $model
506
495
* @return array
507
496
*/
508
497
public function removeRules (Model $ model )
@@ -525,8 +514,6 @@ protected function removeMessages()
525
514
/**
526
515
* Get remove query exception message.
527
516
*
528
- * @param QueryException $exception
529
- * @param Model $model
530
517
* @return string
531
518
*/
532
519
protected function removeExceptionMessage (QueryException $ exception , Model $ model )
@@ -573,39 +560,38 @@ public function unguard($state = true)
573
560
/**
574
561
* Handle uploading of file.
575
562
*
576
- * @param \Illuminate\Http\Request $request
577
563
* @return \Illuminate\Http\JsonResponse
578
564
*/
579
565
public function upload (Request $ request )
580
566
{
581
- $ field = $ request ->input ('uploadField ' );
567
+ $ field = $ request ->input ('uploadField ' );
582
568
$ storage = $ this ->getDisk ();
583
569
584
570
try {
585
- $ rules = $ this ->uploadRules ();
571
+ $ rules = $ this ->uploadRules ();
586
572
$ fieldRules = ['upload ' => $ rules [$ field ] ?? []];
587
573
588
574
$ this ->validate ($ request , $ fieldRules , $ this ->messages (), $ this ->attributes ());
589
575
590
576
$ uploadedFile = $ request ->file ('upload ' );
591
- $ id = $ this ->storeUploadedFile ($ field , $ uploadedFile );
577
+ $ id = $ this ->storeUploadedFile ($ field , $ uploadedFile );
592
578
593
579
if (method_exists ($ this , 'uploaded ' )) {
594
580
$ id = $ this ->uploaded ($ id );
595
581
}
596
582
597
583
return response ()->json ([
598
584
'action ' => $ this ->action ,
599
- 'data ' => [],
600
- 'files ' => [
585
+ 'data ' => [],
586
+ 'files ' => [
601
587
'files ' => [
602
588
$ id => [
603
- 'filename ' => $ id ,
589
+ 'filename ' => $ id ,
604
590
'original_name ' => $ uploadedFile ->getClientOriginalName (),
605
- 'size ' => $ uploadedFile ->getSize (),
606
- 'directory ' => $ this ->getUploadDirectory (),
607
- 'disk ' => $ this ->disk ,
608
- 'url ' => $ storage ->url ($ id ),
591
+ 'size ' => $ uploadedFile ->getSize (),
592
+ 'directory ' => $ this ->getUploadDirectory (),
593
+ 'disk ' => $ this ->disk ,
594
+ 'url ' => $ storage ->url ($ id ),
609
595
],
610
596
],
611
597
],
@@ -615,11 +601,11 @@ public function upload(Request $request)
615
601
]);
616
602
} catch (ValidationException $ exception ) {
617
603
return response ()->json ([
618
- 'action ' => $ this ->action ,
619
- 'data ' => [],
604
+ 'action ' => $ this ->action ,
605
+ 'data ' => [],
620
606
'fieldErrors ' => [
621
607
[
622
- 'name ' => $ field ,
608
+ 'name ' => $ field ,
623
609
'status ' => str_replace ('upload ' , $ field , $ exception ->errors ()['upload ' ][0 ]),
624
610
],
625
611
],
@@ -639,12 +625,11 @@ public function uploadRules()
639
625
640
626
/**
641
627
* @param string $field
642
- * @param UploadedFile $uploadedFile
643
628
* @return string
644
629
*/
645
630
protected function getUploadedFilename ($ field , UploadedFile $ uploadedFile )
646
631
{
647
- return date ('Ymd_His ' ) . '_ ' . $ uploadedFile ->getClientOriginalName ();
632
+ return date ('Ymd_His ' ). '_ ' . $ uploadedFile ->getClientOriginalName ();
648
633
}
649
634
650
635
/**
@@ -665,7 +650,6 @@ protected function getDisk()
665
650
666
651
/**
667
652
* @param string $field
668
- * @param UploadedFile $uploadedFile
669
653
* @return false|string
670
654
*/
671
655
protected function storeUploadedFile ($ field , UploadedFile $ uploadedFile )
0 commit comments