I have a PHP laravel forum application. The application has a Question model below:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Question extends Model
{
protected $fillable = [
'title', 'question'
];
public function user()
{
return $this->belongsTo("App\User")->whereNull('deleted_at');
}
}
The issue is that when the user is soft deleted (deleted_at is not null), the model Question::find() still finds some cases associated with the soft deleted users. In fact, it should return null. My understanding is that there should be a join somewhere in the model to filter out any result that users.deleted_at is not null that I tried but I do not think that this is the right way of doing that. Can someone please comment on this?