Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ public function whereAttachedTo($related, $relationshipName = null, $boolean = '
$this->has(
$relationshipName,
boolean: $boolean,
callback: fn (Builder $query) => $query->whereKey($relatedCollection),
callback: fn (Builder $query) => $query->whereKey($relatedCollection->pluck($related->getKeyName())),
);

return $this;
Expand Down
3 changes: 3 additions & 0 deletions tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ public function testWhereAttachedTo()
{
$related = new EloquentBuilderTestModelFarRelatedStub;
$related->id = 49;
$related->name = 'test';

$builder = EloquentBuilderTestModelParentStub::whereAttachedTo($related, 'roles');

Expand All @@ -1292,9 +1293,11 @@ public function testWhereAttachedToCollection()
{
$model1 = new EloquentBuilderTestModelParentStub;
$model1->id = 3;
$model1->name = 'test3';

$model2 = new EloquentBuilderTestModelParentStub;
$model2->id = 4;
$model2->name = 'test4';

$builder = EloquentBuilderTestModelFarRelatedStub::whereAttachedTo(new Collection([$model1, $model2]), 'roles');

Expand Down
4 changes: 3 additions & 1 deletion tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected function createSchema()

$this->schema($connection)->create('achievements', function ($table) {
$table->increments('id');
$table->integer('status')->nullable();
});

$this->schema($connection)->create('eloquent_test_achievement_eloquent_test_user', function ($table) {
Expand Down Expand Up @@ -1497,7 +1498,7 @@ public function testWhereAttachedTo()
$user1 = EloquentTestUser::create(['email' => '[email protected]']);
$user2 = EloquentTestUser::create(['email' => '[email protected]']);
$user3 = EloquentTestUser::create(['email' => '[email protected]']);
$achievement1 = EloquentTestAchievement::create();
$achievement1 = EloquentTestAchievement::create(['status' => 3]);
$achievement2 = EloquentTestAchievement::create();
$achievement3 = EloquentTestAchievement::create();

Expand Down Expand Up @@ -2988,6 +2989,7 @@ class EloquentTestAchievement extends Eloquent
public $timestamps = false;

protected $table = 'achievements';
protected $guarded = [];

public function eloquentTestUsers()
{
Expand Down