File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
src/Illuminate/Database/Eloquent/Concerns Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -499,6 +499,10 @@ public function getRelationValue($key)
499
499
*/
500
500
public function isRelation ($ key )
501
501
{
502
+ if ($ this ->hasAttributeMutator ($ key )) {
503
+ return false ;
504
+ }
505
+
502
506
return method_exists ($ this , $ key ) ||
503
507
(static ::$ relationResolvers [get_class ($ this )][$ key ] ?? null );
504
508
}
Original file line number Diff line number Diff line change 4
4
5
5
use Exception ;
6
6
use Illuminate \Database \Eloquent \Builder ;
7
+ use Illuminate \Database \Eloquent \Casts \Attribute ;
7
8
use Illuminate \Database \Eloquent \Collection ;
8
9
use Illuminate \Database \Eloquent \Model ;
9
10
use Illuminate \Database \Eloquent \Relations \HasOne ;
@@ -281,6 +282,14 @@ public function testRelationResolvers()
281
282
$ this ->assertInstanceOf (EloquentResolverRelationStub::class, $ model ->customer ());
282
283
$ this ->assertSame (['key ' => 'value ' ], $ model ->customer );
283
284
}
285
+
286
+ public function testIsRelationIgnoresAttribute ()
287
+ {
288
+ $ model = new EloquentRelationAndAtrributeModelStub ;
289
+
290
+ $ this ->assertTrue ($ model ->isRelation ('parent ' ));
291
+ $ this ->assertFalse ($ model ->isRelation ('field ' ));
292
+ }
284
293
}
285
294
286
295
class EloquentRelationResetModelStub extends Model
@@ -351,3 +360,25 @@ public function getResults()
351
360
return ['key ' => 'value ' ];
352
361
}
353
362
}
363
+
364
+ class EloquentRelationAndAtrributeModelStub extends Model
365
+ {
366
+ protected $ table = 'one_more_table ' ;
367
+
368
+ public function field (): Attribute
369
+ {
370
+ return new Attribute (
371
+ function ($ value ) {
372
+ return $ value ;
373
+ },
374
+ function ($ value ) {
375
+ return $ value ;
376
+ },
377
+ );
378
+ }
379
+
380
+ public function parent ()
381
+ {
382
+ return $ this ->belongsTo (self ::class);
383
+ }
384
+ }
You can’t perform that action at this time.
0 commit comments