I'm Having xlsx File With Mulitsheet, Screen Example

I have the first sheet named supporters and it has id field and others fields,
on other hands, the rest of the sheets are named by ids according to the id field on the first sheet supporter.
so basically, every other sheet has additional info to the supporter, so every record on supporter sheet has additional info on the sheet.
for example supporter sheet there is some record has id of 2. and there is sheet called 2 that contain info about record 2.
I want to crap the information in every sheet according to the id
@patrickbrouwers could you help, please?
@zymawy Sounds like you need to first import the first sheet and then dynamically built up the import object based on those results.
Hi @patrickbrouwers,
I have App\Imports\SupportersImport and indeed it load the first sheet as needed to insert it to the table =>
public function model(array $row)
{
$user = User::create([
'name' => $row["alasm"],
'password' => Hash::make($row["rkm_alaadoy"]),
'phone_number' => $row["rkm_aljoal"],
]);
$user->attachRole('supporter');
$user->supporter()->create([
'supporter_code' => $row["rkm_alaadoy"],
'register_at' => $row["tarykh_alashtrak"],
'note' => $row["mlahthat"],
]);
// I need to fill out these tables from other sheet
$user->subscriptionYear()->create([
]);
$user->subscriptionOrder()->create([
]);
return $user;
}
the issue is I have other subscription_orders, subscription_year
I want fill them from some sheet, _I don't know how to crap the other sheet_
any instruction will appreciate it.
The function "model" is called for each sheet. You can put your import-logic for the different sheets in there and switch by name of the sheet.
To determine which sheet will be processed next in the model function you can store that information in a property of your import class.
This property can be filled in the beforeSheet event.
Take a look at this.
https://github.com/Maatwebsite/Laravel-Excel/issues/1881
Looking At It. @CaptainCannabis
@CaptainCannabis Thank You For The Light. But How I Can Grap The Info From The Other Sheet According The Title Name?
@zymawy Define a property like i did with "sheetData" and only pass data into it (in the toArrray-method) if the actual sheetname is the desired one.
public function array(array $array)
{
if($this->sheetNames[count($this->sheetNames)-1] == 'WANTEDSHEET' ){$this->sheetData[$this->sheetNames[count($this->sheetNames)-1]] = $array;
}
After the import you can access that property of your import-object.
@zymawy @CaptainCannabis next release will have a way to skip unknown sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html#skipping-unknown-sheets
And also a trait to indicate which sheets should be loaded, even though more are defined:https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html#conditional-sheet-loading
Most helpful comment
@zymawy @CaptainCannabis next release will have a way to skip unknown sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html#skipping-unknown-sheets
And also a trait to indicate which sheets should be loaded, even though more are defined:https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html#conditional-sheet-loading