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 3 sheets. Sheet 1 validation success, sheet2 validation fails, sheet3 validation success. With this scenario, all import must fail but currently Sheet1Import class insert to database successfully. Please help me. Here is my code.
==================
IMPORT CONTROLLER
public function importMerchant(Request $request)
{
$merchant = Merchant::find($request['merchant_id']);
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
-
The logic is...
I have 3 sheets. Sheet 1 validation success, sheet2 validation fails, sheet3 validation success. With this scenario, all import must fail but currently Sheet1Import class insert to database successfully. Please help me. Here is my code.
==================
IMPORT CONTROLLER
public function importMerchant(Request $request)
{
$merchant = Merchant::find($request['merchant_id']);
}
==================
SHEET IMPORT CLASS
namespace App\Imports;
use App\Models\Merchant;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class MerchantImport implements WithMultipleSheets
{
public function __construct(Merchant $merchant)
{
$this->merchant = $merchant;
}
}
==================
SHEET1 IMPORT CLASS
class Sheet1 implements ToCollection, WithHeadingRow, SkipsEmptyRows, SkipsOnFailure, SkipsOnError, Skips
{
use SkipsFailures, SkipsErrors;
}
==================
SHEET 2 IMPORT CLASS (this is where validation fails)
class MerchantBranchSectionImport implements ToCollection, WithHeadingRow, SkipsEmptyRows
{
/**
* @param Collection $collection
/
public function collection(Collection $rows)
{
Validator::make($rows->toArray(), [
'.section_name' => ['required','string', 'min:3'], //this is where validation fails
'.description' => ['required','string', 'min:3'],
'.order' => ['required','integer'],
'.tags' => ['required','string', 'min:3'],
'.is_active' => ['required','in:1,0']
])->validate();
}
Beta Was this translation helpful? Give feedback.
All reactions