Files
freeu-project/app/Imports/ImportMonthlyP2PFaircent.php
Ritikesh yadav c661166e1d first commit
2024-03-28 14:52:40 +05:30

63 lines
2.2 KiB
PHP

<?php
namespace App\Imports;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use App\Models\MonthlyUpdatePeerToPeerLending;
class ImportMonthlyP2PFaircent implements ToCollection, WithHeadingRow
{
/**
* @param Collection $collection
*/
public function rules(): array
{
// return null;
return [
// '*.issuer' => 'required|unique:bonds,issuer'
// '*.property_name' => 'required|unique:fractional_real_estates,property_name'
// '*.min_investment' => 'required',
// '*.return_rate' => 'required',
];
}
public function customValidationMessages(Collection $rows)
{
$messages = [];
foreach ($rows as $key => $val) {
$messages['' . $key . '.issuer.required'] = 'Issuer should not be empty at row ' . $key + 1;
$messages['' . $key . '.issuer.unique'] = 'Issuer is not unique at row ' . $key + 1;
}
return $messages;
// return [
// '*.property_name.required' => 'Property name must not be empty!'
// // '*.min_investment.required' => 'Minimun Investment must not be empty!',
// // '*.return_rate.required' => 'Return Rate must not be empty!'
// ];
}
public function collection(Collection $rows)
{
Validator::make($rows->toArray(), $this->rules(), $this->customValidationMessages($rows))->validate();
foreach ($rows as $row) {
MonthlyUpdatePeerToPeerLending::create([
'custom_id' => $row['custom_id'],
'total_value' => $row['total_value'],
'investment_amount' => $row['investment_amount'],
'all_time_amount_invested' => $row['all_time_amount_invested'],
'interest_accrued' => $row['interest_accrued'],
'principal_redemption' => $row['principal_redemption'],
'net_interest_redemption' => $row['net_interest_redemption'],
'escrow_balance' => $row['escrow_balance'],
'average_roi' => $row['average_roi'],
]);
}
}
}