Define the relationship with the user's posts.
public posts ( ) : Illuminate\Database\Eloquent\Relations\HasMany | ||
Результат | Illuminate\Database\Eloquent\Relations\HasMany |
/** * Executes the check. * * @todo use only one query, instead of the two seperate queries * * @return void */ protected function execute() { $ips = $this->user->posts()->whereNotNull('ip_address')->lists('ip_address'); $this->report['locations'] = "Ip's used: " . count($ips); $this->report['related'] = []; User::whereHas('posts', function ($q) use($ips) { $q->whereIn('ip_address', $ips); })->where('id', '!=', $this->user->id)->chunk(10, function ($users) { foreach ($users as $user) { $this->report['related'][] = $user->toJson(); } }); }