控制器中仅对特定功能的权限

时间:2019-03-18 15:02:06

标签: laravel laravel-permission

您能告诉我当用户具有不同权限时如何隐藏特定列

进入视图

<table id="student_table" class="table table-bordered" style="width:100%">
  <thead>
    <tr>
      <th>Дата/час</th>
      <th>Отвес блок 1</th>
      <th>Отвес блок 2</th>
      <th>Отвес блок 3</th>
      <th>Отвес блок 4</th>
      <th>Филтрация блок 1</th>
      <th>Филтрация блок 2</th>
      <th>КВН<br>граница: над 814<br> [m]</th>
      <th>Кота дренажен кладенец 1</th>
      <th>Ниво дренажен кладенец 2</th>
      @can('role-1')
      <th>created_at</th>
      <th>updated_at</th>
      <th>author</th>
      <th width="15%">Action</th>
      <th width="2.5%">
          <button type="button" name="bulk_delete" id="bulk_delete" class="btn btn-danger btn-xs">
            <i class="glyphicon glyphicon-remove"></i>
          </button>
        </th>
      @endcan
      </tr>
    </thead>
  </table>

在控制器中

class AjaxdataController extends Controller
{

  function __construct()
  {
   $this->middleware('permission:role-1', ['only' => ['getdata']]);
  }

  function getdata(Request $request)
  {
    $start_date = date('d-m-Y 00:00:00');
    $end_date = date('d-m-Y 23:59:59');
    if($request->start_date != '' && $request->end_date != '')
    {
      // if user fill dates
      $dateScope = array($request->start_date ." 00:00:00", $request->end_date ." 23:59:59");
    } else {
      // default load page - today
      $dateScope = array($start_date, $end_date);
    };
    $students = otv_fil::whereBetween('timestamp', $dateScope)
    ->selectRaw('timestamp,blok9osx,blok9osy,blok11osx,blok11osy,filblok10,filblok11,cvn,ndk,ndk - ? as ndk2,created_at,updated_at,author,id',[743.38])
    ->orderBy('timestamp', 'ASC')
    ->get();
    return Datatables::of($students)
    ->addColumn('action', function($student){
      return '<a href="#" class="btn btn-xs btn-primary edit" id="'.$student->id.'"><i class="glyphicon glyphicon-edit"></i> Edit</a><a href="#" class="btn btn-xs btn-danger delete" id="'.$student->id.'"><i class="glyphicon glyphicon-remove"></i> Delete</a>';
    })
    ->addColumn('checkbox', '<input type="checkbox" name="student_checkbox[]" class="student_checkbox" value="{{$id}}" />')
    ->rawColumns(['checkbox','action'])
    ->make(true);
  }
}

问题在于,我不知道如何在构造函数中告知该权限仅适用于getdata中的列。 有什么方法可以分割功能吗?

此刻,当用户在页面中没有权限时,页面加载时出现jquery Uncaught TypeError: Cannot read property 'style' of undefined 错误 在该示例中,我仅复制一个函数,而完整代码中不止一个函数

0 个答案:

没有答案