我可以在控制器中使用Helper @can吗?

时间:2019-07-01 14:42:11

标签: php laravel-5 datatables

我的控制器中有此代码

public function index()
   {
       if(request()->ajax())
       {
           return datatables()->of(User::latest()->get())
               ->addColumn('action', function($data){
                   $button = '<a href="#" name="show" id="'.$data->id.'" class="show-modal"><i title="Visualizar" style="color: #00897b;" class="material-icons">visibility</i></a>';
                   $button .= '&nbsp;&nbsp;';
                   $button .= '<a href="#" name="edit" id="'.$data->id.'" class="edit-modal"><i title="Editar" style="color: black;" class="material-icons">edit</i></a>';
                   $button .= '&nbsp;&nbsp;';
                   $button .= '<a href="#" name="delete" id="'.$data->id.'" class="delete-modal"><i title="Excluir" style="color: red;" class="material-icons">delete</i></a>';
                   return $button;
               })
               ->rawColumns(['action'])
               ->make(true);
       }
       return view('admin.usuarios.index');
   }

我可以在按钮中使用辅助功能@can吗?像这样:

$button = '@can ('isAdmin') <a href="#" name="show" id="'.$data->id.'" class="show-modal"><i title="Visualizar" style="color: #00897b;" class="material-icons">visibility</i></a> @endCan';

0 个答案:

没有答案