Home > Article > Backend Development > laravel5.4 data filling example sharing
This article mainly shares laravel5.4 data filling examples with you, hoping to help everyone.
php artisan make:seeder ManagerSeeder
After the execution is completed, ManagerSeeder.php will be generated in the database/seeds directory. There is only the run method in this file
<?php use Illuminate\Database\Seeder; class ManagerSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { \DB::table('manager')->insert( ['username'=>'admin', 'password'=>bcrypt('123456')]//数据库的字段必须是password ); } }
The effect is as follows:
Note:
1. In the data table, the password field must be password
2. In the password field, use bcryptEncryption, this function can be queried in the auxiliary function
php artisan db:seed --class=ManagerSeeder
Description: If there is no parameter class will only Execute all seed files once
At this point, the data filling is completed
Related recommendations:
How to migrate data and fill data in Laravel?
The above is the detailed content of laravel5.4 data filling example sharing. For more information, please follow other related articles on the PHP Chinese website!