Skip to content

Commit b79050d

Browse files
committed
fix conflicts
2 parents 62db29f + ffee0f9 commit b79050d

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

eloquent-relationships.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,6 @@ If your parent model does not use `id` as its primary key, or you wish to join t
120120
return $this->belongsTo('App\User', 'foreign_key', 'other_key');
121121
}
122122

123-
<a name="default-models"></a>
124-
#### Default Models
125-
126-
The `belongsTo` relationship allows you to define a default model that will be returned if the given relationship is `null`. This pattern is often referred to as the [Null Object pattern](https://en.wikipedia.org/wiki/Null_Object_pattern) and can help remove conditional checks in your code. In the following example, the `user` relation will return an empty `App\User` model if no `user` is attached to the post:
127-
128-
/**
129-
* Get the author of the post.
130-
*/
131-
public function user()
132-
{
133-
return $this->belongsTo('App\User')->withDefault();
134-
}
135-
136-
To populate the default model with attributes, you may pass an array or Closure to the `withDefault` method:
137-
138-
/**
139-
* Get the author of the post.
140-
*/
141-
public function user()
142-
{
143-
return $this->belongsTo('App\User')->withDefault([
144-
'name' => 'Guest Author',
145-
]);
146-
}
147-
148-
/**
149-
* Get the author of the post.
150-
*/
151-
public function user()
152-
{
153-
return $this->belongsTo('App\User')->withDefault(function ($user) {
154-
$user->name = 'Guest Author';
155-
});
156-
}
157-
158123
<a name="one-to-many"></a>
159124
### One To Many
160125

@@ -942,6 +907,41 @@ When removing a `belongsTo` relationship, you may use the `dissociate` method. T
942907

943908
$user->save();
944909

910+
<a name="default-models"></a>
911+
#### Default Models
912+
913+
The `belongsTo` relationship allows you to define a default model that will be returned if the given relationship is `null`. This pattern is often referred to as the [Null Object pattern](https://en.wikipedia.org/wiki/Null_Object_pattern) and can help remove conditional checks in your code. In the following example, the `user` relation will return an empty `App\User` model if no `user` is attached to the post:
914+
915+
/**
916+
* Get the author of the post.
917+
*/
918+
public function user()
919+
{
920+
return $this->belongsTo('App\User')->withDefault();
921+
}
922+
923+
To populate the default model with attributes, you may pass an array or Closure to the `withDefault` method:
924+
925+
/**
926+
* Get the author of the post.
927+
*/
928+
public function user()
929+
{
930+
return $this->belongsTo('App\User')->withDefault([
931+
'name' => 'Guest Author',
932+
]);
933+
}
934+
935+
/**
936+
* Get the author of the post.
937+
*/
938+
public function user()
939+
{
940+
return $this->belongsTo('App\User')->withDefault(function ($user) {
941+
$user->name = 'Guest Author';
942+
});
943+
}
944+
945945
<a name="updating-many-to-many-relationships"></a>
946946
### Many To Many Relationships
947947

validation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ The field under validation must exist on a given database table.
694694

695695
'state' => 'exists:states'
696696

697+
If the `column` option is not specified, the field name will be used.
698+
697699
#### Specifying A Custom Column Name
698700

699701
'state' => 'exists:states,abbreviation'

0 commit comments

Comments
 (0)