Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to get property 'conversation' of non-object #29

Open
shresthabiswas opened this issue Apr 15, 2020 · 0 comments
Open

Trying to get property 'conversation' of non-object #29

shresthabiswas opened this issue Apr 15, 2020 · 0 comments

Comments

@shresthabiswas
Copy link

shresthabiswas commented Apr 15, 2020

I have just tried to run your demo codes after everything has been installed into the domain server. The error encountered into my laravel 7 application. Let me show you where actually the issue occurred.
This is home.blade.php

@foreach($threads as $inbox)
                       @if($inbox->message->conversation->is_accepted) <!-- This is the line of code where error has been encountered -->
                           <a href="{{ route('chat' , [
                               'id' => $inbox->message->conversation->id
                           ]) }}">
                               <div class="about">
                                   <div class="name">{{$inbox->user->name}}</div>
                                   <div class="status">
                                       @if(auth()->user()->id == $inbox->message->sender->id)
                                           <span class="fa fa-reply"></span>
                                       @endif
                                       <span>{{ substr($inbox->message->text, 0, 20)}}</span>
                                   </div>
                               </div>
                           </a>
                       @else
                           <a href="#">
                               <div class="about">
                                   <div class="name">{{$inbox->user->name}}</div>
                                   <div class="status">
                                       @if(auth()->user()->id == $inbox->message->sender->id)
                                           <span class="fa fa-reply"></span>
                                       @endif
                                       <span>{{ substr($inbox->message->text, 0, 20)}}</span>
                                   </div>
                                   @if($inbox->message->conversation->second_user_id == auth()->user()->id)
                                       <div>
                                           <a href="{{ route('accept.message' , [
                               'id' => $inbox->message->conversation->id
                           ]) }}" class="btn btn-xs btn-success">Accept Message Request</a>
                                       </div>
                                   @endif
                               </div>
                           </a>
                       @endif

               @endforeach

This is HomeController.php index()

public function index()
   {
       $groups = Chat::getAllGroupConversations();
       $threads = Chat::getAllConversations();

       return view('home')->with([
           'threads' => $threads,
           'groups'  => $groups
       ]);
   }

When I dump and die into the $threads[0]->message, I find #relations null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant