laravel5.4 data filling example sharing

小云云
Release: 2023-03-21 14:10:01
Original
1521 people have browsed it

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
Copy after login

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
        );
    }
}
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template