Search code examples
laravellaravel-5.3packageyajra-datatable

@(at) syntax can't render in controller to view yajra datatables


i write @ syntax in addcolumn on return datatables, but @ syntax can't render in blade template, @ syntax only plaintext. how i can render @ syntax?

data source data()

view

this my code: http://pastebin.com/Sc2eG6us

can any help me? thank you before


Solution

  • Do it the other way around, add the columns only if they have the permissions.

    $postsDataTable = Datatables::of($posts);
    
    $actionButton = '';    
    if(\Entrust::can('pengguna-view')){  
       $actionButton = '<button name="button-drop" class="lihat-data btn-sm btn btn-default "
           data-id="'.$datas->id.'"
           data-username="'.$datas->username.'"
           data-attribute="'.$datas->attribute.'"
           data-op="'.$datas->op.'"
           data-value="'.$datas->value.'"
           data-barcode="'.$datas->barcode.'"
           data-flag="'.$datas->flag.'"
           data-dismiss="modal">
           <span class="glyphicon glyphicon-eye-open" aria-hidden="true"> Lihat</span>
         </button>';
    }
    
       $postsDataTable = $postsDataTable->addColumn('action',function($datas) use ($actionButton) {
          return $actionButton;
      });
    }
    
    return $postsDataTable->make(true);