ํค๋ ํ์ ๊ฑด๋๋ฐ๊ณ ๋ ๋ฒ์งธ ํ์์ ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ์์ํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
์ข๋ค:
class UsersImport implements ToModel
{
/**
* <strong i="13">@param</strong> array $row
*
* <strong i="14">@return</strong> User|null
*/
public function model(array $row)
{
return new User([
'name' => $row[0],
'email' => $row[1],
'password' => Hash::make($row[2]),
]);
}
}
๊ทธ๋ฐ๋ฐ ๋ ๋ฒ์งธ ์ค๋ถํฐ? ๋ฐ๋ผ์ ํค๋ ์ด๋ฆ์ ๋ํด ๊ฑฑ์ ํ ํ์๊ฐ ์์ต๋๋ค. ์ด ์์๋ง ์์ผ๋ฉด ๋ฉ๋๋ค.
๋๋ ๊ทธ๊ฒ์ ํด๊ฒฐํ๋ค
class UsersImport implements ToModel, WithStartRow
{
...
/**
* <strong i="6">@return</strong> int
*/
public function startRow(): int
{
return 2;
}
}
๋๋ ๋น์ ์ด ์ด๋ฏธ ์ด๊ฒ์ ํด๊ฒฐํ๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง ์ด๊ฒ์ ํ ์ ์๋ ๋ด์ฅ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค: WithHeadingRow
๋๋ ๋น์ ์ด ์ด๋ฏธ ์ด๊ฒ์ ํด๊ฒฐํ๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง ์ด๊ฒ์ ํ ์ ์๋ ๋ด์ฅ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค: WithHeadingRow
๊ทธ๋ฌ๋ WithHeadingRow
ํ๋ฉด ์ธ๋ฑ์ค๋ก ํ ํญ๋ชฉ์ ์ก์ธ์คํ ์ ์์ต๋๋ค.
๋ฉ์ง!
๋ซํ ์๋ค๋ ๊ฒ์ ์๊ณ ์์ง๋ง @lcardosozago ์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋ค์์ ์ถ๊ฐํ๋ ๊ฒ์ ์์ง ๋ง์ญ์์ค.
use Maatwebsite\Excel\Concerns\WithStartRow;
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ๊ทธ๊ฒ์ ํด๊ฒฐํ๋ค