HTML Code in Datatable in Laravel 5.4, not parsing code in webpage, in Laravel 5.3.* is working ok.
The same behavior on your demo page: Eloquent DataTable with Array Response in Action column.
Environment: Laravel 5.4, Acacha\Adminlte
public function data()
{
DB::statement(DB::raw('set @rownum=0'));
$result = My_Model::select(array(
DB::raw('@rownum := @rownum + 1 AS rownum'),
'created_at',
'name'));
$datatables = Datatables::eloquent($result)
->editColumn('rownum', '<div style="text-align:center;"><a class="btn btn-primary btn-xs">{{ $rownum }}</a></div>')
->editColumn('created_at','<div style="text-align:center;">{{ App\Functions::setDateTime($created_at) }}')
->editColumn('name', '<div style="text-align:left;"><a class="btn btn-success btn-xs">{{ $name}}</a></div>');
return $datatables->make(true);
}
Result displayed in datatable in webpage, just this text, not a button with value 1:
<div style="text-align:center;"><a class="btn btn-primary btn-xs">1</a></div>
Solved with solution from: #909
Adding rawColumns:
$datatables = Datatables::eloquent($result)->rawColumns(['rownum','created_at','name'])
...
The same behavior on your demo page: Eloquent DataTable with Array Response in Action column. 馃憤
I couldn't get ->rawColumns([]) to work though, after trying whole day :(. Had to resolve grudgingly to escapeColumns([]).
Any ideas why this might happen? Thanks.
What's the solution?
public function datatab(User $user)
{
$users = $user->all();
return Datatables::of($users)
->editColumn('name', function ($model) {
return '<a href="'.url('/data/users/' . $model->id . '/edit').'">'.$model->name.'</a>';
})
->make(true);
}
whats the solution for this? rawColumn doesn't work. and escapeColumn basically removes HTML tags and only displays the image address. When I use editColumn
->editColumn('image', function ($product_brand) {
return '<img src="'.$product_brand->image.'" style="height:30px; width:30px" />';
})
it just shows the html code in the image column
<
img src="https://randomuser.me/api/portraits/men/1.jpg" style="height:30px; width:30px" /
>
Please let me know the solution where I can display this image.
:(
same here @mailnike
any solution ????
The solution for @bayodesegun is escapeColumns([]). This disables the xss protection.
$users = $user->all();
return Datatables::of($users)
->editColumn('name', function ($model) {
return '<a href="'.url('/data/users/' . $model->id . '/edit').'">'.$model->name.'</a>';
})
->escapeColumns([])
->make(true);
I think using the HTML from laravel collective will also work.
$users = $user->all();
return Datatables::of($users)
->editColumn('name', function ($model) {
return Html::link(route('model.edit', $model), $model->name);
})
->make(true);
->escapeColumns([]) its working
Most helpful comment
Solved with solution from: #909
Adding rawColumns:
$datatables = Datatables::eloquent($result)->rawColumns(['rownum','created_at','name']) ...The same behavior on your demo page: Eloquent DataTable with Array Response in Action column. 馃憤