Skip to content

Commit c4548ab

Browse files
committed
Ensure accessor values can be reached
1 parent f70f47f commit c4548ab

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

tests/ActivityLoggerTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@
227227
expect($this->getLastActivity()->description)->toEqual($expectedDescription);
228228
});
229229

230-
it('can replace the placeholders deeply', function () {
231-
$article = Article::create(['name' => 'article name']);
230+
it('can replace the placeholders with object properties and accessors', function () {
231+
$article = Article::create([
232+
'name' => 'article name',
233+
'user_id' => User::first()->id
234+
]);
232235

233236
$article->foo = new stdClass();
234237
$article->foo->bar = new stdClass();
@@ -237,9 +240,9 @@
237240
activity()
238241
->performedOn($article)
239242
->withProperties(['key' => 'value', 'key2' => ['subkey' => 'subvalue']])
240-
->log('Subject name is :subject.name, deeply nested property is :subject.foo.bar.baz');
243+
->log('Subject name is :subject.name, deeply nested property is :subject.foo.bar.baz, accessor property is :subject.owner_name');
241244

242-
$expectedDescription = 'Subject name is article name, deeply nested property is zal';
245+
$expectedDescription = 'Subject name is article name, deeply nested property is zal, accessor property is name 1';
243246

244247
expect($this->getLastActivity()->description)->toEqual($expectedDescription);
245248
});

tests/Models/Article.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ class Article extends Model
1010

1111
protected $guarded = [];
1212

13-
public function User()
13+
public function user()
1414
{
1515
return $this->belongsTo(User::class);
1616
}
17+
18+
public function getOwnerNameAttribute()
19+
{
20+
return $this->user?->name;
21+
}
1722
}

0 commit comments

Comments
 (0)