this is my laravel custom accessor which I am appending using
protected $appends = [leave_balances];
public function getLeaveBalancesAttribute() {
// some code
}
I want to pass a parameter when I am calling this accessor like this
public function getLeaveBalancesAttribute($parameter) {
// use $parameter here
}
$payslip = Payslip::find(1);
\Log::debug($payslip->leave_balances("PARAMETER"));
I have searched and found that it is not possible. please can some one provide any solution to this I need to pass this parameter.
If you declare an Attribute, you can only use it like this (following your example:
What you (I think) want is
setLeaveBalancesAttribute, so you can pass a value and do whatever you want with it:But, if you are using Laravel 9+, please do use the new way of defining attributes, it is better.