BREAD accessors
Sometimes you want to format an attribute only for one (or some) of the BREAD-actions. For example if you have a name field and on the browse-page you want to display something when the field is empty, you define the following in your model:
1
<?php
2
3
public function getNameBrowseAttribute()
4
{
5
return $this->name ?? 'Empty';
6
}
Copied!
This will display "Empty" if the actual field is empty, or return the value if not.
Likewise you can do the same for the other BREAD-actions:
1
<?php
2
3
public function getNameReadAttribute()
4
{
5
//
6
}
7
8
public function getNameEditAttribute()
9
{
10
//
11
}
12
13
public function getNameAddAttribute()
14
{
15
//
16
}
Copied!
Last modified 1mo ago
Export as PDF
Copy link