laravelamazon-elastic-beanstalkwas

Laravel error after uploading to AWS


I built a simple website with laravel and it runs fine on my local machine. However, when I upload it to the AWS only one page gives me errors!

The error message:

Undefined offset: 1 (View: /var/app/current/resources/views/admin.blade.php)

The other error:

Undefined offset: 1

After some debugging, I found out this code causes the error:

<?php
     // visitors number
     $q = DB::table('visitors')->select('visitors')->get(); 
     $t = "$q";
     $r = explode(":", $t);
     $nr = explode("}", $r[1]);
     $vis = $nr[0];

     // sub number
     $q = DB::table('visitors')->select('sub_visitors')->get(); 
     $t = "$q";
     $r = explode(":", $t);
     $nr = explode("}", $r[1]);
     $sub = $nr[0]; 
?> 

I know it is not the best practice to put the php code inside the view but I am a beginner in laravel and I was in a hurry. And the explode method because the results was in a format like json (I don't think that it was json). How can I solve it in this way.


Solution

  • That is not Json and you dont need to explode it, those are objects of class you can use it like this to access a particular column(visitors in your case) of your result

    $q = DB::table('visitors')->select('visitors')->get();
    foreach($q as $item){
       echo $item->visitors;
    }