nahid / talk

Talk is a real-time users messaging and chatting system for Laravel.
MIT License
1.61k stars 326 forks source link

undefined relationship [sender] on model [Nahid\Talk\Messages\Message]. #100

Open x1mdev opened 7 years ago

x1mdev commented 7 years ago

Hi, i'm trying to implement Talk into my project but i'm getting this error:

RelationNotFoundExceptionCall to undefined relationship [sender] on model [Nahid\Talk\Messages\Message].
--
in RelationNotFoundException.php (line 34)
at RelationNotFoundException::make(object(Message), 'sender')in Builder.php (line 546)
at Builder->Illuminate\Database\Eloquent\{closure}()
at call_user_func(object(Closure))in Relation.php (line 89)
at Relation::noConstraints(object(Closure))in Builder.php (line 548)
at Builder->getRelation('sender')in Builder.php (line 516)
at Builder->eagerLoadRelation(array(object(Message)), 'sender', object(Closure))in Builder.php (line 496)
at Builder->eagerLoadRelations(array(object(Message)))in Builder.php (line 464)
at Builder->get(array('*'))in Relation.php (line 154)
at Relation->get()in Relation.php (line 143)

This happens when I try to send a message to a user.

I could not find the issue in my project, so I installed a fresh nahid/talk-example and configured it as told.

The above error is copied from the error page I got in the talk-example application again trying to send a message->does not work-> refresh page-> get error. It also happens when i return to /home (in talk-example) and try to send message to another user.

Anyone else had this issue?

c2gahlot commented 7 years ago

Same issue.

[2017-11-24 11:03:14] local.ERROR: Call to undefined relationship [sender] on model [Nahid\Talk\Messages\Message]. {"userId":1,"email":"c2xxxx@zoho.com","exception":"[object] (Illuminate\Database\Eloquent\RelationNotFoundException(code: 0): Call to undefined relationship [sender] on model [Nahid\Talk\Messages\Message]. at /home/vagrant/store/vendor/laravel/framework/src/Illuminate/Database/Eloquent/RelationNotFoundException.php:34)

Please Help!

ABwabsolute commented 6 years ago

Same here when i try to get all the messages by User id and pass them to view.

$myMessages = Talk::getMessagesByUserId(Auth::user()->id); return view('messaging.list', compact('myMessages', 'myMessages'));

EDIT: Found The Solution for my case:

Added to UserModel

Check this Docs https://laravel.com/docs/5.1/eloquent#soft-deleting

Don't forget the new migration for the SoftDeletes...

shrihub commented 6 years ago

Same issue. Kindly resolve.

jtallinger commented 6 years ago

If you dont want to use softdelete on your user model, then just add a dummy withTrash function in the user model: public function scopeWithtrashed($query) { return $query; }