Skip to content

Commit 772c152

Browse files
Mark accessor and mutators as protected
When I saw Taylor's comment I though this would be a great practice to encourage. In fact, another benefit of marking this methods as protected is that they will not be displayed by the IDE during auto-completion in other classes. laravel/framework#40022 (comment)
1 parent e877592 commit 772c152

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

eloquent-mutators.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ In this example, we'll define an accessor for the `first_name` attribute. The ac
4646
* @param string $value
4747
* @return string
4848
*/
49-
public function getFirstNameAttribute($value)
49+
protected function getFirstNameAttribute($value)
5050
{
5151
return ucfirst($value);
5252
}
@@ -67,7 +67,7 @@ You are not limited to interacting with a single attribute within your accessor.
6767
*
6868
* @return string
6969
*/
70-
public function getFullNameAttribute()
70+
protected function getFullNameAttribute()
7171
{
7272
return "{$this->first_name} {$this->last_name}";
7373
}
@@ -95,7 +95,7 @@ Let's define a mutator for the `first_name` attribute. This mutator will be auto
9595
* @param string $value
9696
* @return void
9797
*/
98-
public function setFirstNameAttribute($value)
98+
protected function setFirstNameAttribute($value)
9999
{
100100
$this->attributes['first_name'] = strtolower($value);
101101
}

0 commit comments

Comments
 (0)