Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Binapick's avatar

controller send html tags with replaced < >

I am using laravel 8 and yajra datatables to display data. I now have to output some data with html tags. However, the controller replaces all < and > with the html codes < and > I can't get my datatable script to display the tags correctly. How can I instruct the controller or the script how to deal with the tags? Adding {!! it does not work. Have anyone a idea how can i solve my problem?

Andreas

´´´

public function index( Request $request ) { if( $request->ajax() ) {

  $tbl = ( new User )->table;
  $query = User::select( sprintf( '%s.*', $tbl ) );
  $table = Datatables::of( $query );
  $table->addColumn( 'roles', function( $row ) {
    $roles = '';
    foreach( $row->roles as $key => $item ) {
      $roles .= '<span class="badge badge-info">' . $item->title . '</span>';
    }
    return $roles;
  } );
  return $table->make( true );
}
return view( 'admin.users.index' ); 

} ´´´ in my js i get : &lt;span class=&quot;badge badge-info&quot;&gt;Admin&lt;/span&gt;

´´´ columns: [ { data: 'name', name: 'name' }, { data: 'email', name: 'email' }, { data: 'roles', name: 'roles', render: function( data ) { return data; } } ], ´´´

0 likes
0 replies

Please or to participate in this conversation.