Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaraCSV doesn't respect accessors? #57

Open
brendandebeasi opened this issue Sep 6, 2022 · 2 comments
Open

LaraCSV doesn't respect accessors? #57

brendandebeasi opened this issue Sep 6, 2022 · 2 comments

Comments

@brendandebeasi
Copy link

I have a model based on https://github.com/jenssegers/model, which in my experience, behaves exactly like an eloquent model.

I have a model defined

namespace App\Models;

use Jenssegers\Model\Model;

class Ec2Usage extends Model
{
    public string $account;
    public string $name;
    public string $id;
    public string $type;
    public float $onDemandCostPerHour;
    public float $onDemandCostPerYear;
    public float $oneYearReserveCostUpFront;
    public float $oneYearReserveCostPerHour;
    public float $oneYearReserveCostPerYear; // includes upfront
    public float $cpuMin;
    public float $cpuMax;
    public float $cpuAvg;

    public function getOnDemandCostPerYearAttribute($value)
    {
        return $this->onDemandCostPerHour * 8760;
    }

    public function getOneYearReserveCostPerYearAttribute($value)
    {
        return ($this->oneYearReserveCostPerHour * 8760) + $this->oneYearReserveCostUpFront;
    }
}

However when I create the report it does not seem that the accessor is being used:

    private function createReport() {
        $csvExporter = new Export();
        $csvExporter->build(
            $this->report,
            ['account','id','type','onDemandCostPerHour','onDemandCostPerYear','oneYearReserveCostPerYear','cpuMin','cpuMax','cpuAvg']
        )->download();
    }
@saularis
Copy link
Contributor

saularis commented Sep 6, 2022

@brendandebeasi Does it work without accessor?

@brendandebeasi
Copy link
Author

@saularis Yes, if they are explicitly set values. These accessors are setup to return a value based on another value, so in that case they don't seem to work.

I'll do some digging around and see if I can locate the root cause, but not sure if anything comes to mind / this is expected functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants