【问题标题】:How to Add Button with Permission on Datatables Laravel如何在数据表 Laravel 上添加具有权限的按钮
【发布时间】:2019-06-07 11:24:19
【问题描述】:

我是数据表的初学者。我已经成功地在每一行上添加了一个按钮。但是,我遇到了一个问题。如何添加权限,如

@can ('theresia-create')
//button
@endcan

如果在刀片上,我可以使用@can 和@endcan,但在这里不能。那么,我该怎么办?

控制器

    return Datatables::of($kamar)
    ->addColumn('action', function ($data) {
        return '
        <form action="'. route('kamar_theresia.destroy', $data->id) .'" method="POST">
        <a href="kamar_theresia/'.$data->id.'" class="btn btn-xs btn-info"><i class="fa fa-eye"></i> Show</a>
        <a href="kamar_theresia/'.$data->id.'/edit" class="btn btn-xs btn-primary"><i class="fa fa-edit"></i> Edit</a>
        <input type="hidden" name="_method" value="DELETE">
        <input type="hidden" name="_token" value="'. csrf_token() .'">
        <button class="btn btn-xs btn-danger btn-delete" data-remote="kamar_theresia/'.$data->id.'" data-toggle="confirmation"><i class="fa fa-trash"></i> Delete</a></button>
        </form>
        ';
    })
    ->editColumn('id', 'ID: {{$id}}')
    ->make(true);

查看

<table id="kamar" class="text-center table table-bordered">
  <thead class="text-capitalize">
    <tr>
      <th>Name</th>
      <th>Kelas</th>
      <th>Ketersediaan</th>
      <th>Action</th>
    </tr>
  </thead>
</table>

<script type="text/javascript">
    var editor;
    $('#kamar').DataTable({
        responsive: true,
        processing: true,
        serverSide: true,
        ajax: 'http://localhost:8000/dataTheresia',
        columns: [
            {data: 'nama', name: 'kamar_theresia.nama'},
            {data: 'name', name: 'kelas_theresia.name'},
            {data: 'ketersediaan', name: 'kamar_theresia.ketersediaan'},
            {data: 'action', name: 'action', orderable: false, searchable: false},
            ]
        });
</script>

【问题讨论】:

  • '@can ('theresia-create') //button @endcan'等权限

标签: laravel yajra-datatable


【解决方案1】:
<form action="'. route('kamar_theresia.destroy', $data->id) .'" method="POST">
 {{ csrf_field() }}
        <a href="kamar_theresia/'.$data->id.'" class="btn btn-xs btn-info"><i class="fa fa-eye"></i> Show</a>
        <a href="kamar_theresia/'.$data->id.'/edit" class="btn btn-xs btn-primary"><i class="fa fa-edit"></i> Edit</a>
        <input type="hidden" name="_method" value="DELETE">
        <input type="hidden" name="_token" value="'. csrf_token() .'">
        <button class="btn btn-xs btn-danger btn-delete" data-remote="kamar_theresia/'.$data->id.'" data-toggle="confirmation"><i class="fa fa-trash"></i> Delete</a></button>
        </form>

【讨论】:

  • {{ csrf_field() }} ,我添加了它,它出现在页面上。
猜你喜欢
  • 2014-04-23
  • 1970-01-01
  • 2021-05-15
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
  • 2020-04-06
  • 2020-12-10
  • 1970-01-01
相关资源
最近更新 更多