File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
laravel/database/eloquent/relationships Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -7,16 +7,25 @@ class Has_One_Or_Many extends Relationship {
7
7
/**
8
8
* Insert a new record for the association.
9
9
*
10
+ * If save is successful, the model will be returned, otherwise false.
11
+ *
10
12
* @param Model|array $attributes
11
- * @return bool
13
+ * @return Model|false
12
14
*/
13
15
public function insert ($ attributes )
14
16
{
15
- $ attributes = ($ attributes instanceof Model) ? $ attributes ->attributes : $ attributes ;
16
-
17
- $ attributes [$ this ->foreign_key ()] = $ this ->base ->get_key ();
17
+ if ($ attributes instanceof Model)
18
+ {
19
+ $ attributes ->set_attribute ($ this ->foreign_key (), $ this ->base ->get_key ());
20
+
21
+ return $ attributes ->save () ? $ attributes : false ;
22
+ }
23
+ else
24
+ {
25
+ $ attributes [$ this ->foreign_key ()] = $ this ->base ->get_key ();
18
26
19
- return $ this ->model ->create ($ attributes );
27
+ return $ this ->model ->create ($ attributes );
28
+ }
20
29
}
21
30
22
31
/**
You can’t perform that action at this time.
0 commit comments