1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures; |
4
|
|
|
|
5
|
|
|
trait AjaxTable { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Respond with the JSON of one or more rows, depending on the POST parameters. |
9
|
|
|
* @return JSON Array of cells in HTML form. |
|
|
|
|
10
|
|
|
*/ |
11
|
|
|
public function search() |
12
|
|
|
{ |
13
|
|
|
$this->crud->hasAccessOrFail('list'); |
|
|
|
|
14
|
|
|
|
15
|
|
|
// crate an array with the names of the searchable columns |
16
|
|
|
$columns = collect($this->crud->columns) |
17
|
|
|
->reject(function ($column, $key) { |
|
|
|
|
18
|
|
|
// the select_multiple columns are not searchable |
19
|
|
|
return isset($column['type']) && $column['type'] == 'select_multiple'; |
20
|
|
|
}) |
21
|
|
|
->pluck('name') |
22
|
|
|
// add the primary key, otherwise the buttons won't work |
23
|
|
|
->merge($this->crud->model->getKeyName()) |
24
|
|
|
->toArray(); |
25
|
|
|
|
26
|
|
|
// structure the response in a DataTable-friendly way |
27
|
|
|
$dataTable = new \LiveControl\EloquentDataTable\DataTable($this->crud->query, $columns); |
28
|
|
|
|
29
|
|
|
// make the datatable use the column types instead of just echoing the text |
30
|
|
|
$dataTable->setFormatRowFunction(function ($entry) { |
31
|
|
|
// get the actual HTML for each row's cell |
32
|
|
|
$row_items = $this->crud->getRowViews($entry, $this->crud); |
33
|
|
|
|
34
|
|
|
// add the buttons as the last column |
35
|
|
|
if ($this->crud->buttons->where('stack', 'line')->count()) { |
36
|
|
|
$row_items[] = \View::make('crud::inc.button_stack', ['stack' => 'line']) |
37
|
|
|
->with('crud', $this->crud) |
38
|
|
|
->with('entry', $entry) |
39
|
|
|
->render(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// add the details_row buttons as the first column |
43
|
|
|
if ($this->crud->details_row) { |
44
|
|
|
array_unshift($row_items, \View::make('crud::columns.details_row_button') |
45
|
|
|
->with('crud', $this->crud) |
46
|
|
|
->with('entry', $entry) |
47
|
|
|
->render()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $row_items; |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
return $dataTable->make(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
} |
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.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.