'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) { if($row['investment_value'] != null && $row['total_net_interest'] != null && $row['total_gross_interest'] != null && $row['total_value_of_the_property'] != null) { MonthlyUpdateFractionalRealEstate::create([ 'custom_id' => $row['custom_id'], 'total_value_of_the_property' => $row['total_value_of_the_property'] ?? 0, 'investment_value' => $row['investment_value'] ?? 0, 'investment_date' => $row['investment_date'], 'total_gross_interest' => $row['total_gross_interest'] ?? 0, 'tds' => $row['tds'] ?? 0, 'total_net_interest' => $row['total_net_interest'] ?? 0, 'gross_entry_yield' => $row['gross_entry_yield'] ?? 0, 'target_return' => $row['target_return'] ?? 0, 'absolute_return_till_date' => $row['absolute_return_till_date'], ]); } } } }