0

I'm trying to render a view with čćžšđ letters in it, but it's failing and giving me this error:

The Response content must be a string or object implementing __toString(), \"boolean\" given."

I extracted a partial, and when I load this partial using normal way (with @include) then everything is ok. But I need "load more" function, so I'm using this partial to render html for me, and I only append it to DOM using jQuery. This is the partial:

<?php $flag = true; ?>
@foreach($tags as $tag)
    @if(empty($tag->tag)) <?php continue; ?> @endif
    @if($flag == true)
        <?php $temp = $tag->tag[0]; ?>
            <br><label class="firstLetterLabel">{{ strtoupper($temp) }}</label><br><hr><br>
        <?php $flag = false; ?>
    @endif
    @if($temp != $tag->tag[0])
        <br><label class="firstLetterLabel">{{ strtoupper($tag->tag[0]) }}</label><br><hr><br>
    @endif
    <div class="singleTag">
        <a href="/tag/{{ $tag->id }}">{{ $tag->tag }}</a>
    </div>
    <?php $temp = $tag->tag[0]; ?>
@endforeach

This is how I use it in "load more" function:

$tags = Tag::orderBy("tag")->take(Config::get("settings.num_tags_per_page"))->skip(($page-1)*Config::get("settings.num_tags_per_page"))->get();

    $data = array();
    $data['data'] = View::make("discover.partials.tags")->with("tags", $tags)->render();


    if(count($tags)%Config::get("settings.num_tags_per_page") == 0 && count($tags) > 0)
        $data['msg'] = 'ok';
    else
        $data['msg'] = 'stop';

    return json_encode($data);

This partial read tags and sort them alphabetically, and it extracts first letter of every tag because I need that letter somewhere else. And when this partial finds one of these letters čćžšđ then it gives me above error.

How to solve this?

Alen
  • 1,750
  • 7
  • 31
  • 62

2 Answers2

1

Try this:

json_encode($output, JSON_UNESCAPED_UNICODE)
bjb568
  • 11,089
  • 11
  • 50
  • 71
Jeremie Ges
  • 2,747
  • 3
  • 22
  • 37
0

For future notice, I solved this problem by replacing $tag->tag[0] with mb_substr($tag->tag, 0, 1). This command extracts utf-8 characters from string while my previous approach wasn't properly encoding utf-8 chars.

More info here: Get first character of UTF-8 string

Community
  • 1
  • 1
Alen
  • 1,750
  • 7
  • 31
  • 62