You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a multiple sheets (different import class each) that inserts in different table that needs validation.
I need to failed the overall import when a sheet validation failed.
Currently my code is insert the sheets with success validation and stop when a sheet validation failed.
Here is my code.
class MerchantImport implements WithMultipleSheets
{
public function __construct(Merchant $merchant)
{
$this->merchant = $merchant;
}
public function sheets(): array
{
return [
'merchant_branch' => new MerchantBranchImport($this->merchant),
'merchant_branch_sections' => new MerchantBranchSectionImport(),
'merchant_items' => new MerchantItemImport()
];
}
}
Class MerchantBranchImport implements ToCollection, WithHeadingRow, SkipsEmptyRows
{
public function __construct(Merchant $merchant)
{
$this->merchant = $merchant;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a multiple sheets (different import class each) that inserts in different table that needs validation.
I need to failed the overall import when a sheet validation failed.
Currently my code is insert the sheets with success validation and stop when a sheet validation failed.
Here is my code.
class MerchantImport implements WithMultipleSheets
{
public function __construct(Merchant $merchant)
{
$this->merchant = $merchant;
}
}
Class MerchantBranchImport implements ToCollection, WithHeadingRow, SkipsEmptyRows
{
public function __construct(Merchant $merchant)
{
$this->merchant = $merchant;
}
}
Class MerchantBranchSectionImport implements ToCollection, WithHeadingRow, SkipsEmptyRows
{
/**
* @param Collection $collection
/
public function collection(Collection $rows)
{
Validator::make($rows->toArray(), [
'.section_name' => ['required','string', 'min:3'],
'.description' => ['required','string', 'min:3'],
'.order' => ['required','integer'],
'.tags' => ['required','string', 'min:3'],
'.is_active' => ['required','in:1,0']
])->validate();
}
AND HERE IS THE CONTROLLER
public function importMerchant(Request $request)
{
$merchant = Merchant::find($request['merchant_id']);
}
Beta Was this translation helpful? Give feedback.
All reactions