Cov txheej txheem:

Dab tsi yog database seeder hauv laravel?
Dab tsi yog database seeder hauv laravel?

Video: Dab tsi yog database seeder hauv laravel?

Video: Dab tsi yog database seeder hauv laravel?
Video: yog hmoov dab tsi. Zoo Xyooj (cover) 2024, Kaum ib hlis
Anonim

Laravel suav nrog txoj kev yooj yim ntawm noob koj database nrog cov ntaub ntawv xeem siv cov chav kawm noob. Tag nrho cov chav kawm noob yog khaws cia rau hauv lub database / noob directory. Los ntawm chav kawm no, koj tuaj yeem siv txoj hauv kev hu los khiav lwm cov chav kawm noob, uas tso cai rau koj los tswj cov noob xaj.

Raws li txoj cai, kev cog qoob loo database txhais li cas?

Database seeding yog pib noob ntawm a database nrog cov ntaub ntawv. Seeding ib database yog ib tug txheej txheem nyob rau hauv uas ib tug thawj txheej ntawm cov ntaub ntawv yog muab rau a database thaum nws yog raug ntsia. Cov ntaub ntawv tuaj yeem yog cov ntaub ntawv dummy lossis cov ntaub ntawv tsim nyog xws li thawj tus thawj tswj hwm tus account.

Tsis tas li ntawd, kev tsiv teb tsaws thiab kev cog qoob loo yog dab tsi? Taw qhia Migration thiab Seeding Kev tsiv teb tsaws yog zoo li kev tswj hwm version rau koj cov ntaub ntawv, tso cai rau koj pab neeg kom hloov kho tau yooj yim thiab sib qhia daim ntawv thov cov ntaub ntawv schema. Kev tsiv teb tsaws yog feem ntau ua ke nrog Laravel's schema builder kom yooj yim tsim koj daim ntawv thov database schema.

Ua kom pom qhov no, koj siv lub seeder li cas?

Yuav Siv Lub Vaj Seeder Li Cas

  1. Kauj Ruam 1 – Xaiv cov noob. Koj yuav tsum tsis txhob ntub cov noob ua ntej koj siv lub vaj seeder.
  2. Kauj Ruam 2 – Xaiv cov noob daim phiaj. Lub vaj seeder xav tau cov noob kom raug, nyob ntawm seb cov qoob loo twg koj xav cog.
  3. Kauj Ruam 3 - Siv Cov Seeder Los Sow Noob.
  4. Kauj Ruam 4 - Siv Seeder los Fertilize qoob loo.

Kuv yuav khiav lub Hoobkas hauv laravel li cas?

Rau siv qhov txhais Hoobkas (txawm los ntawm koj qhov kev sim lossis cov noob), peb siv tus Hoobkas muaj nuj nqi muab los ntawm laravel . // tsim ib tus neeg siv thiab khaws cia rau hauv database $user = Hoobkas (AppUser::class)->create(); Qhov no tsim ib tus neeg siv. Txhawm rau tsim ntau tus neeg siv - tsuas yog dhau qhov ntsuas thib ob mus rau qhov Hoobkas muaj nuj nqi.

Pom zoo: