forked from CodeToWeb/Laravel-DatatablesEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatatablesController.php
executable file
·76 lines (54 loc) · 1.89 KB
/
DatatablesController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\User;
use Auth;
use App\Http\Requests\DatatablesFormRequest;
use Validator;
// use Datatables;
use yajra\Datatables\Datatables;
use App\Helpers\DatatablesEditor;
class DatatablesController extends Controller {
public function index() {
return view('datatable-editor');
}
/**
* Process datatables ajax request.
*
* @return \Illuminate\Http\JsonResponse
*/
public function anyData() {
$dtRes = Datatables::of(User::select('*'))
->make(true);
return $dtRes;
}
/**[dataResponse2 description]
*
* @param Request $req
* @return JSON JSON response
*/
public function dataResponse(Request $req) {
$input = $req->input();
$action = $input['action'];
$rowIdArray = array_keys($input['data']);
foreach($rowIdArray as $rowId) {
$dataArray[] = $input['data'][$rowId];
}
// do form validation
$validator = Validator::make($input['data'][$rowIdArray[0]], [
'first_name' => 'required|max:5',
'last_name' => 'required|max:30'
]);
$validator->setCustomMessages([
'first_name.required' => 'Please provide your first name.',
'first_name.max' => 'Please shorten your first name.',
'last_name.required' => 'Please provide your last name.',
'last_name.max' => 'Please shorten your last name.',
]);
$returnArray = DatatablesEditor::process($req, $validator, /* 'App\Models\User' */ /* User::all() */ User::where ('id', '<=', 50) );
// This was used to create static json responses for testing purposes
// $returnArray = DatatablesEditor::processStaticTest($req, $validator, 'App\Models\User');
return $returnArray;
}
}