Start -> Run -> Cmd
, trỏ đường dẫn đến thư mục project sunshine
c:\xampp\htdocs\sunshine
cd c:\xampp\htdocs\sunshine
artisan
để tạo SEED
trong LaravelLoại
php artisan make:seeder LoaiTableSeeder
LoaiTableSeeder
sẽ được tạo trong thư mục `database\seeds\LoaiTableSeeder.php`Loại
<?php use Illuminate\Database\Seeder; class LoaiTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { $list = []; $types = ["Hoa lẻ", "Phụ liệu", "Bó hoa", "Giỏ hoa", "Hoa hộp giấy", "Kệ hoa", "Vòng hoa", "Bình hoa", "Hoa hộp gỗ"]; sort($types); $today = new DateTime('2019-01-01 08:00:00'); for ($i=1; $i <= count($types); $i++) { array_push($list, [ 'l_ma' => $i, 'l_ten' => $types[$i-1], 'l_taoMoi' => $today->format('Y-m-d H:i:s'), 'l_capNhat' => $today->format('Y-m-d H:i:s') ]); } DB::table('cusc_loai')->insert($list); } }
SEED
, cập nhật dữ liệu ban đầu cho table Loại
php artisan db:seed --class=LoaiTableSeeder
Loại
có dữ liệu ban đầu đúng với code trong file SEED hay không?SEED table LOAI
: https://github.com/kellyfire611/sunshinenew/blob/master/database/seeds/LoaiTableSeeder.php
Thực hiện các bước tuần tự theo nội dung Bài học nhé!
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!