Laravel relationship and retrieve data

  eloquent, laravel, php, pivot, relationship

I have problem…I have to import data from Excel and my code works well. All data are downloaded to database. Next step is to prepare pivot table from imported data. Problem is that I have 1 column with budget account like: "502-407-80-M1-GD522UF", "502-401-03-M2" etc. How to get data to two other columns: project where I need to read it from budget account column? Code of project is 400,401,402,407 etc and how to get account type also from budget account like: M1, M2 etc.
I need it to prepare pivot table with costs depending on project, type and date.
I tried with Eloquent relationship like:

$amortization = IndirectCost::where(‘account’, ‘like’, ‘%400%’)
->sum(‘payment’);
but I’m not sure its good way to solve this problem.

And how to prepare relationship with date, for example I have 02.09.2021, 04.09.2021 etc and I want to prepare new column with "09.2021" to sum all datas with 09.2021.

Thank you for your help!:)

Source: Ask PHP

LEAVE A COMMENT