Skip to content

Commit

Permalink
Remove whereHas in alreadyCreated() since whereHas doesn’t work with …
Browse files Browse the repository at this point in the history
…polymorphics at this time.
  • Loading branch information
Alex Gomory committed May 24, 2017
1 parent df83e20 commit bf3c187
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/Laranote.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,20 @@ private function alreadyCreated()
{
$note = $this->note;

$existingNotes = Note::with('regarding')->whereHas('noting', function ($q) use ($note) {
$q->where('id', $note->noting->id);
})->where('content', $note->content)->get();
// Word around since whereHas currently don't work for polyMorphics (https://github.com/laravel/framework/issues/5429)
$existingNotes = Note::where('content', $note->content)->get()->filter(function ($value, $key) use ($note) {

if($existingNotes->count() == 0) {
return false;
}

if(!$note->regarding) {
return true;
}
if ($value->noting->id != $note->noting->id) {
return false;
}

foreach($existingNotes as $existingNote) {
if($existingNote->regarding && ($existingNote->regarding->id == $note->regarding->id)) {
return true;
if ($note->regarding && (!$value->regarding || ($value->regarding->id != $note->regarding->id))) {
return false;
}
}

return true;
});

return false;
return ($existingNotes->count() > 0);
}
}

0 comments on commit bf3c187

Please sign in to comment.