title: Using Laravel 5.6 Blade to send PHP array as JSON string or JSON Object to JS Frontend
body: <blockquote>
    <p>I am struggling with trying to identify the best approach for sending the PHP array as JSON
    string or JSON Object to frontend JavaScript using Laravel 5.6 Blade
    template.</p>
  </blockquote>
  
  <p>It seems like when I do the following in Blade template file it never convert it to string. </p>
  
  <pre><code> @php $vueModel = [ ...] @endPhp
  
    &lt;script&gt;
        sessionStorage.setItem('vueModel', {!! json_encode($vueModel) !!} );
        ...
    &lt;/script&gt;
  </code></pre>
  
  <p>It shows as an <strong>[Object Object]</strong> in the Chrome dev tools.</p>
  
  <p>So after this if I try to do the following it will not work (there will be errors):</p>
  
  <pre><code> let model = JSON.parse(sessionStorage.getItem('vueModel'));
  </code></pre>
  
  <p>But if I do the following trick, then it spit out the string.</p>
  
  <blockquote>
    <p>Please notice the single quote surrounding  '{!! ... !!}'</p>
  </blockquote>
  
  <pre><code>&lt;script&gt;
    sessionStorage.setItem('vueModel', '{!! json_encode($vueModel) !!}' );
    ...
  </code></pre>
  
  <p></p>
  
  <p>However, this has its own problem because now I get the string with backslash encoded quotes and then I will have to fix that.</p>
  
  <blockquote>
    <p>So what is the clean way to send the PHP array as a either JSON Object
    or JSON String without any encoding to Frontend JavaScript using laravel 5.6 Blade template language ? What is
    the recommended approach in this situation?</p>
  </blockquote>