0

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.

8
  • What is the error message? What exactly are you trying to achieve with this code? Commented Aug 22, 2017 at 9:24
  • @Jerodev sorry I just noticed that I didn't put the error message , anyway I updated the question and the error is now visible Commented Aug 22, 2017 at 9:26
  • You shouldn't manually break up an object from a json string, what exactly are you trying to achieve with this code? Are you getting a field from the database? Commented Aug 22, 2017 at 9:31
  • @Jerodev yes I have a visitors counter and a conversion counter (how many visitors have filled a form in the home page) but if it works on the local machine why it is not working on the AWS? Commented Aug 22, 2017 at 9:34
  • Possibly because the field does not exist in your database. Can you post what your database looks like, then I can help you to properly get the data from your database. Commented Aug 22, 2017 at 9:35

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.