我想使用 laravel 集合在 yajra 数据表的另一列上输出一个可点击的删除按钮。问题是它{!! Form::open(["action" => ["UsersController@destroy",28], "method" => "POST", "class" => "pull-right"]) !!} {{ Form::hidden("_method", "DELETE") }} {{ Form::submit("Delete", ["class" => "btn btn-danger"]) }} {!! Form::close()!!}")
在视图中输出原始 html 文本,而不是可点击的删除按钮。我可以输出常规的 html 标签,但我想使用 laravel 集合。我很困惑为什么即使我已经添加了rawColumns()
功能它也不起作用。
这是我的控制器:
public function yajraDT()
{
$users = User::all();
return Datatables::of($users)
->addColumn('delete', function ($users) {
return '{!! Form::open(["action" => ["UsersController@destroy",'.$users->id.'], "method" => "POST", "class" => "pull-right"]) !!}
{{ Form::hidden("_method", "DELETE") }}
{{ Form::submit("Delete", ["class" => "btn btn-danger"]) }}
{!! Form::close()!!}")';
})
->rawColumns(['delete'])
->make(true);
}
这是我的看法:
<script>
$(function() {
$('#tableDT').DataTable({
processing: true,
serverSide: true,
ajax: '{{ url('users/yajraDT') }}',
columns: [
{ data: 'id', name: 'id',
@if(Auth::check() && Auth::user()->type == "Admin")
render:function(data, type, row)
{
return "<a href='/users/"+ row.id +"'>" + row.id + "</a>"
}
@endif},
{ data: 'first_name', name: 'first_name' },
{ data: 'last_name', name: 'last_name' },
{ data: 'email', name: 'email' },
{ data: 'gender', name: 'gender' },
{data: 'delete', name: 'delete'}
]
});
});
</script>