title: Array works fine on localhost but not working on live server (gives error message Undefined offset: 0) - Laravel-5.8
body: <p>Everything works perfectly okay on localhost but when migrated to godaddy live server(cpanel) I keep getting this error (Undefined offset: 0) on my blade view</p>
  
  <p>I have tested the application on my localhost using XAMPP running PHP 7.2.12 and it works very fine but now I moved it to godaddy cpanel running PHP 7.3 and it keeps giving me this error</p>
  
  <p>//This is my Route
  Route::get('/conversations', 'DoctorsController@Conversations');</p>
  
  <p>//This is my Controller
  public function Conversations(Request $request){</p>
  
  <pre><code>    //authenticate user
      if($request-&gt;us == 'guest'){
  
          return redirect()-&gt;intended('login');
  
      }else{
  
      $unread=DB::table('messaging')
              -&gt;where([
                      ['Reciever', Auth::user()-&gt;id],
                      ['ReadStatus', '=', '']
                      ])
              -&gt;get();
  
  
      $pending=$unread-&gt;count();
  
      //retrieve previous chat;
      $conversations=DB::table('messaging')
                  -&gt;where('Sender', Auth::user()-&gt;id)
                  -&gt;orWhere('Reciever', Auth::user()-&gt;id)
                  -&gt;groupBy('Sender')
                  -&gt;orderBy('ReadStatus', 'asc')
                  -&gt;get();
  
      //retrieve profile of users in the previous chat
      $profiles = array();
      $read_status = array();
      foreach($conversations as $conversation){
      if($conversation-&gt;Sender == Auth::user()-&gt;id){
  
      //check user role to know which database to query
      $userRole=DB::table('role_user')
              -&gt;where('user_id', $conversation-&gt;Reciever)
              -&gt;get();
  
      if($userRole[0]-&gt;role_id === 2){
  
          #retrieve the sender details from doctors table
          $profile=DB::table('doctors')
                      -&gt;where('doctor_id', $conversation-&gt;Reciever)
                      -&gt;get();
  
  
      }else{
  
          //retrieve the sender details from users table
          $profile=DB::table('profiles')
                      -&gt;where('user_id', $conversation-&gt;Reciever)
                      -&gt;get();
  
      }
  
  
          if(in_array($profile, $profiles)){
  
          }else{
          array_push($profiles, $profile);
  
          }
  
          //retrieve the reciever details
      }else if($conversation-&gt;Reciever == Auth::user()-&gt;id){
  
          //check user role to know which database to query
          $userRole=DB::table('role_user')
                  -&gt;where('user_id', $conversation-&gt;Sender)
                  -&gt;get();
  
          if($userRole[0]-&gt;role_id === 2){
  
              $profile=DB::table('doctors')
                      -&gt;where('doctor_id', $conversation-&gt;Sender)
                      -&gt;get();
  
  
          }else{
  
  
              $profile=DB::table('profiles')
                      -&gt;where('user_id', $conversation-&gt;Sender)
                      -&gt;get();
  
  
          }
  
          //retrive unread chat;
              $unreadconvers=DB::table('messaging')
                  -&gt;select('ReadStatus')
                  -&gt;where([
                          ['Reciever', Auth::user()-&gt;id],
                          ['Sender', $conversation-&gt;Sender],
                          ['ReadStatus', '=', '']
                          ])
                  -&gt;get();
  
  
              if(in_array($profile, $profiles)){
  
              }else{
              $profile['unreads'] = $unreadconvers-&gt;count();
              array_push($profiles, $profile);
              //array_push($read_status, $unreadconvers-&gt;count());
  
              }
  
  
          }
  
          $i++;
      }
  
      return view('conversations')-&gt;with(['profile'=&gt;$profiles, 'pending'=&gt;$pending, 'unreads'=&gt;$read_status]);
      //return to the conversation blade
  
      }
  }
  </code></pre>
  
  <p>//This is my Blade template
  @foreach($profile as $profile)</p>
  
  <pre><code>      &lt;div class="col-md-4 element-animate"&gt;
          &lt;div class="media d-block media-custom text-center"&gt;
            &lt;img src= "{{ URL::to(isset($profile[0]-&gt;image) ? $profile[0]-&gt;image : '../img/user.png') }}" alt="Image Placeholder" class="img-fluid img-fluid-doctors"&gt;
            &lt;div class="media-body"&gt;
              &lt;a href="{{ isset($profile[0]-&gt;doctor_id) ? url('/chat-doctor?db='.$profile[0]-&gt;doctor_id) : url('/chat-doctor?us='.$profile[0]-&gt;user_id)  }}" class="envelop"&gt;&lt;i class="far fa-envelope"&gt;&lt;/i&gt;&lt;span class="unread"&gt;{{ isset($profile['unreads']) ? $profile['unreads'] : 0 }}&lt;/span&gt;
              &lt;h3 class="mt-0 text-black"&gt;{{ $profile[0]-&gt;name }}&lt;/h3&gt;
              &lt;/a&gt;
  
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
        @endforeach
  </code></pre>
  
  <p>At the Controller, this code is expected to retrieve all the messages from the database linking to the logged in user either send or received, store them using an array and display them at the blade template looping through each of the array.</p>
  
  <p>Currently that is what it does on localhost but on live server I get this error message Undefined offset: 0 (View: /resources/views/conversations.blade.php)</p>