我已经在项目中安装了yajra laravel,我尝试使用带有id的html按钮添加操作列,我正在使用yajra laravel,这些是我的yajra laravel版本:
如何使用带有数据ID的html按钮添加“操作”列?
这是我的数据表代码,用于在laravel中创建数据表:
public function html()
{
$brands = Brands::select(array('brands.id','brands.name','brands.slug','brands.description','brands.logo','brands.published','brands.created_at','brands.updated_at'));
return $this->builder()
->columns($this->getColumns())
->minifiedAjax()
// ->addAction(['width' => '80px'])
->removeColumn('id')
->addColumn($this->actionColumns())
->parameters($this->getBuilderParameters());
}
这是我在laravel中制作数据表的完整代码: https://pastebin.com/v1qYGNjb
我想在“操作”列中添加按钮编辑和删除,如何使用laravel datatables 8做到这一点? 我正在使用laravel数据表作为服务。
答案 0 :(得分:1)
public function html()
{
$brands = Brands::select(array('brands.id','brands.name','brands.slug','brands.description','brands.logo','brands.published','brands.created_at','brands.updated_at'));
return $this->builder()
->columns($this->getColumns())
->minifiedAjax()
// ->addAction(['width' => '80px'])
->removeColumn('id')
->addColumn('action',function ($data){
return $this->getActionColumn($data);
})
->parameters($this->getBuilderParameters());
}
/**
* @param $data
* @return string
*/
protected function getActionColumn($data): string
{
$showUrl = route('admin.brands.show', $data->id);
$editUrl = route('admin.brands.edit', $data->id);
return "<a class='waves-effect btn btn-success' data-value='$data->id' href='$showUrl'><i class='material-icons'>visibility</i>Details</a>
<a class='waves-effect btn btn-primary' data-value='$data->id' href='$editUrl'><i class='material-icons'>edit</i>Update</a>
<button class='waves-effect btn deepPink-bgcolor delete' data-value='$data->id' ><i class='material-icons'>delete</i>Delete</button>";
}
答案 1 :(得分:1)
main_repository
|-- .gitmodules
|-- .git
| `-- modules
| `-- submodule_xy .git files
|-- submodule_xy
|-- .gitmodules
`-- submodule_files