nahid / talk

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

Error viewing/showing messages from soft-deleted users #91

Closed tviles closed 6 years ago

tviles commented 6 years ago

The User relationship in the Messages model needs to have ->withTrashed() to allow messages to be viewed even if the user has been soft-deleted. Otherwise it throws an error.

Before: public function user() { return $this->belongsTo(config('talk.user.model', 'App\User')); }

After: public function user() { return $this->belongsTo(config('talk.user.model', 'App\User'))->withTrashed(); }

jtallinger commented 6 years ago

Hi, This change is now in dev-version, which breaks functionality for projects which do not use soft delete on user model. Add work around for those cases? Config?

/r Simple scope added to User model did the trick.. public function scopeWithtrashed($query) { return $query; }