-
BUT if I want to create a form with a table set up with specific fields, and not with the default ones how can I do? I'm trying I created the form with the command you described and then I modified the table but now I don't see anything in the administrator side table list, in the public side I see the inserted fields but there is nothing in the administrative side table, I removed the name, slug, description field and I put the columns I need but they are not visible.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
If you have checked the Backend controller of the new module, there are no methods. If you want to add/update columns in the index page, you have to add the index_datatable method in the backend controller as well. Check the BackendBaseController and you will get the methods. |
Beta Was this translation helpful? Give feedback.
-
You have to add the following method in your controller public function index_data()
{
$module_title = $this->module_title;
$module_name = $this->module_name;
$module_path = $this->module_path;
$module_icon = $this->module_icon;
$module_model = $this->module_model;
$module_name_singular = Str::singular($module_name);
$module_action = 'List';
$page_heading = label_case($module_title);
$title = $page_heading.' '.label_case($module_action);
$$module_name = $module_model::select('id', 'name', 'updated_at');
$data = $$module_name;
return Datatables::of($$module_name)
->addColumn('action', function ($data) {
$module_name = $this->module_name;
return view('backend.includes.action_column', compact('module_name', 'data'));
})
->editColumn('name', '<strong>{{$name}}</strong>')
->editColumn('updated_at', function ($data) {
$module_name = $this->module_name;
$diff = Carbon::now()->diffInHours($data->updated_at);
if ($diff < 25) {
return $data->updated_at->diffForHumans();
} else {
return $data->updated_at->isoFormat('llll');
}
})
->rawColumns(['name', 'action'])
->orderColumns(['id'], '-:column $1')
->make(true);
} then you have to update the following line and include the columns you want to display in the index table $$module_name = $module_model::select('id', 'name', 'updated_at'); then you have to update the <script type="module">
$('#datatable').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
ajax: '{{ route("backend.$module_name.index_data") }}',
columns: [{
data: 'id',
name: 'id'
},
{
data: 'name',
name: 'name'
},
{
data: 'updated_at',
name: 'updated_at'
},
{
data: 'action',
name: 'action',
orderable: false,
searchable: false
}
]
});
</script> |
Beta Was this translation helpful? Give feedback.
-
thanks, great |
Beta Was this translation helpful? Give feedback.
You have to add the following method in your controller