yajra / laravel-datatables-html

Laravel DataTables HTML Builder Plugin
https://yajrabox.com/docs/laravel-datatables/html-installation
MIT License
272 stars 61 forks source link

How we can pass the arguments parameter for the method makeIfCan() #197

Closed CWSPS154 closed 1 year ago

CWSPS154 commented 1 year ago

https://github.com/yajra/laravel-datatables-html/blob/3aaf1c19eb70713858e0ff88ac872e3386bbb4c1/src/Html/HasAuthorizations.php#L57 Core Class - Illuminate\Foundation\Auth\Access\Authorizable image Yajra\DataTables\Html\HasAuthorizations::makeIfCan() image

CWSPS154 commented 1 year ago

Could you give some example for how to use the method makeIfCan

yajra commented 1 year ago

Use case: column or field is only visible for admin?

Column::makeIfCan('admin', 'secret_column'),

On Editor,

Select::makeIfCan('admin', 'role')
CWSPS154 commented 1 year ago

@yajra Thank You for you reply. For me, I have to apply a Gate Gate::allows('have-access','create_role') in the makeIfCan, but there is no option to pass the the argument for the gate option

yajra commented 1 year ago

You can also use Column::makeIf(Gate::allows('have-access','create_role'), 'column')

CWSPS154 commented 1 year ago

How we can use for a computed column Column::computed('action') ->title(__('datatable.action')) ->exportable(false) ->printable(false) ->width(60),

yajra commented 1 year ago

Computed is just a shortcut for searchable=false and orderable=false.

CWSPS154 commented 1 year ago

@yajra When I use this code for action column, it return this error DataTables warning: table id=permission-table - Requested unknown parameter '6' for row 0, column 6. For more information about this error, please see http://datatables.net/tn/4