title: "Trying to get property of non-object" in AJAX request using Laravel?
body: <p>I am building a page that loads content in it.</p>
  
  <p>The page is called /ajax and in here I have a set of data that is pulled in and I basically use this as a url to grab data for loading more images into a container from the instagram php library I have used.</p>
  
  <p>When I press 'load more' it thinks and in the 'network' tab in the console I see this:</p>
  
  <blockquote>
    <p>Trying to get property of non-object</p>
  </blockquote>
  
  <p>The confusion here for me is when I access the url /ajax I get this in the page with the correct data in it:</p>
  
  <p><code>"data_text":"Philips #outfitgrid #barbour"</code> in the array of items so it is clearly there and it can be accessed but for some reason when the url is then passed with <code>/ajax?tag=folkclothing&amp;max_tag_id=1377007699427&amp;_=1377709072077</code> it blows up?</p>
  
  <p>Here is my php for the ajax array:</p>
  
  <pre><code>  $images = array();
    $data_link = array();
    $data_id = array();
    $data_likes = array();
    $data_text = array();
    foreach ($media as $data) {
      $images[] = array(
  
          "data_url"=&gt;$data-&gt;images-&gt;standard_resolution-&gt;url,
          "data_link"=&gt;$data-&gt;link,
          "data_text"=&gt;$data-&gt;caption-&gt;text,
          //"data_text" =&gt; array['$data-&gt;caption-&gt;text'],
          "data_id"=&gt;$data-&gt;getId(),
          "data_likes"=&gt;$data-&gt;likes-&gt;count,
          "data_like"=&gt;$current_user-&gt;likes($data),
          "data_token"=&gt;$token
  
      );
    }
    $object = (object)$data_text;
    echo json_encode(array(
      'next_id' =&gt; $media-&gt;getNextMaxTagId(),
      'images'  =&gt; $images,
      'data_text' =&gt; $data_text
    ));
  </code></pre>
  
  <p>And then I have ajax to get this data into the page:</p>
  
  <pre><code>$.ajax({
            type: 'GET',
            url: '/ajax',
            data: {
              tag: tag,
              max_tag_id: maxid
            },
            dataType: 'json',
            cache: false,
            complete: function(){
            },
            success: function(data) {
              // Output data
              $.each(data.images, function(i, src) {
              var $content = $('&lt;article class="instagram-image"&gt;&lt;form id="'+ data.images[i].data_token +'" class="forms status-'+ data.images[i].data_like +'" action="'+base+'" method="post"&gt;&lt;a class="fancybox" rel="folk-1" href="' + data.images[i].data_url + '"&gt;&lt;img alt="' + data.images[i].data_text + '" src="' + data.images[i].data_url + '" alt="' + data.images[i].data_text + '" /&gt;&lt;/a&gt;&lt;div class="formSubmit-feedback"&gt;&lt;/div&gt;&lt;input type="hidden" name="id" value="'+ data.images[i].data_id +'"&gt;&lt;p&gt;'+ data.images[i].data_likes +'&lt;/p&gt;&lt;/form&gt;&lt;/article&gt;');
                  var duration = 1000, n = 0.1;
                $content.appendTo('section#images');
                $item = $content.find('form');
                if( $item.hasClass("status-false") ){
                      $item.addClass("notLiked");
                      //$('.notLiked').find('button.unlike').hide();
                      $item.find('a').after('&lt;button class="ajax instabtn button-like like icon-heart" type="submit" name="action" value="Like"&gt;&lt;/button&gt;');
                  }
                  if( $item.hasClass("status-true") ){
                      $item.addClass("Liked");
                      //$('.Liked').find('button.like').hide();
                      $item.find('a').after('&lt;button class="ajax instabtn button-unlike unlike icon-heart" type="submit" name="action" value="Unlike"&gt;&lt;/button&gt;');
                  }
                });
              // Store new maxid
              $('#more').data('maxid', data.next_id);
            }
  </code></pre>
  
  <p>Can anyone shed some light into why this may throw the error in my question. I have tried so many solutions but I am struggling to see what the solution is to it.</p>