Home  >  Article  >  Backend Development  >  laravel5.4 data filling example sharing

laravel5.4 data filling example sharing

小云云
小云云Original
2018-03-15 13:55:041518browse

This article mainly shares laravel5.4 data filling examples with you, hoping to help everyone.

1. Execute the artisan command to simulate data for the manager

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(&#39;manager&#39;)->insert(
            [&#39;username&#39;=>&#39;admin&#39;, &#39;password&#39;=>bcrypt(&#39;123456&#39;)]//数据库的字段必须是password
        );
    }
}

The effect is as follows:
laravel5.4 data filling example sharing
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

2. Execute the seed command

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn