Skip to content

Commit 3c910b6

Browse files
committed
as conditions
1 parent 7e4adca commit 3c910b6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

eloquent-relationships.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,20 @@ public function featuredPosts(): HasMany
725725
}
726726
```
727727

728-
The `withAttributes` method will add `where` clause constraints to the query using the given attributes, and it will also add the given attributes to any models created via the relationship method:
728+
The `withAttributes` method will add `where` conditions to the query using the given attributes, and it will also add the given attributes to any models created via the relationship method:
729729

730730
```php
731731
$post = $user->featuredPosts()->create(['title' => 'Featured Post']);
732732

733733
$post->featured; // true
734734
```
735735

736+
To instruct the `withAttributes` method to not add `where` conditions to the query, you may set the `asConditions` argument to `false`:
737+
738+
```php
739+
return $this->posts()->withAttributes(['featured' => true], asConditions: false);
740+
```
741+
736742
<a name="many-to-many"></a>
737743
## Many to Many Relationships
738744

eloquent.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,14 +1594,22 @@ class Post extends Model
15941594
}
15951595
```
15961596

1597-
The `withAttributes` method will add `where` clause constraints to the query using the given attributes, and it will also add the given attributes to any models created via the scope:
1597+
The `withAttributes` method will add `where` conditions to the query using the given attributes, and it will also add the given attributes to any models created via the scope:
15981598

15991599
```php
16001600
$draft = Post::draft()->create(['title' => 'In Progress']);
16011601

16021602
$draft->hidden; // true
16031603
```
16041604

1605+
To instruct the `withAttributes` method to not add `where` conditions to the query, you may set the `asConditions` argument to `false`:
1606+
1607+
```php
1608+
$query->withAttributes([
1609+
'hidden' => true,
1610+
], asConditions: false);
1611+
```
1612+
16051613
<a name="comparing-models"></a>
16061614
## Comparing Models
16071615

0 commit comments

Comments
 (0)