title: Laravel collect to array
body: <p>I try to get my products visits number into charts where I can show it just like google-analytic </p>
  
  <h3>example</h3>
  
  <pre><code>Product1   200 visits
  product5   30 visits
  product10  47visits
  </code></pre>
  
  <p>Now what I'm using as chart is <a href="https://github.com/ConsoleTVs/Charts" rel="nofollow noreferrer">this package</a> </p>
  
  <h1>Here is my chart code:</h1>
  
  <pre><code>$chartjson = Pagevisit::all()-&gt;toJson();
    $chartjsontitle =
        DB::table('products')
        -&gt;join('page-visits', function ($join) {
            $join-&gt;on('products.id', '=', 'page-visits.visitable_id');
        })-&gt;get();
  $value = collect($chartjsontitle)-&gt;toArray();
  
  $chart4 = Charts::database($chartjson, 'bar', 'highcharts')
           -&gt;elementLabel("Total")
           -&gt;dimensions(1000, 500)
           -&gt;responsive(false)
           -&gt;values('visitable_id')
           -&gt;labels($value);
  </code></pre>
  
  <p>As you can see my visits count will save in <code>page-visits</code> table and what I want to do is o get count of that in my chart and as label get product title.</p>
  
  <h2>Progress:</h2>
  
  <ul>
  <li>I've done getting count of my visits already</li>
  </ul>
  
  <blockquote>
    <p>$chartjson = Pagevisit::all()->toJson();
            //....
        ->values('visitable_id')</p>
  </blockquote>
  
  <ul>
  <li>I <strong>couldn't</strong> get my products title as labels for those counts.</li>
  </ul>
  
  <p>Error I'm getting currently is:</p>
  
  <blockquote>
    <p>array_push() expects parameter 1 to be array, string given</p>
  </blockquote>
  
  <h1>UPDATE</h1>
  
  <p>I managed to get my info  + their title</p>
  
  <p><a href="https://i.stack.imgur.com/ClFcr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ClFcr.png" alt="screenshot"></a></p>
  
  <h3>Here is the code</h3>
  
  <pre><code>$chartjson = Pagevisit::all()-&gt;pluck('visitable_id')-&gt;toArray();
        $chartjsontitle =
            DB::table('products')
            -&gt;join('page-visits', function ($join) {
                $join-&gt;on('products.id', '=', 'page-visits.visitable_id');
            })-&gt;pluck('title')-&gt;toArray();
  
        $chart4 = Charts::database($chartjson, 'bar', 'highcharts')
           -&gt;elementLabel("Total")
           -&gt;dimensions(1000, 500)
           -&gt;responsive(false)
           -&gt;values($chartjson)
           -&gt;labels($chartjsontitle);
  </code></pre>
  
  <h1>ISSUE</h1>
  
  <p>I have 2 products which have visits counted but as you see for each count I have one bar except 1 bar for all counts.</p>
  
  <ul>
  <li>example: 1 bar with title product1 and count of 11 visits, but now I have 11 bars with title product1</li>
  </ul>