lavarel video project of backnet -- 1. Data migration

Keywords: PHP Database Laravel shell

1, Summary

One sentence summary:

1. The data migration of lavarel is relatively simple, which is to create data tables with php
2. Create migration file: PHP artican make: migration create? HD? Table -- create = HD
3. Create the migration file as a table: PHP artican migrate

 

1. Install barryvdh / laravel ide helper to add code prompt: https://packagist.org search barryvdh?

1,composer require --dev barryvdh/laravel-ide-helper
2,Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
3,php artisan ide-helper:generate
1,Require this package with composer using the following command:
composer require --dev barryvdh/laravel-ide-helper
2,After updating composer, add the service provider to the providers array in config/app.php
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
3,You can now re-generate the docs yourself (for future updates)
php artisan ide-helper:generate

 

 

2. When uploading the code to github, there is no need to submit it under the vendor directory. How to restore it when downloading the project?

You can use composer install directly, which is the configuration of composer.json

 

3. What is the principle of database migration in laravel?

Using php to operate the database

 

4. How to do database migration in lavarel?

1. Create the migration file: PHP artican make: migration create? HD? Table -- create = HD
2. Execute the file in database\migrations: PHP artican migrate

After the second step, the table will be created

 

5. What are the common differences between MySQL 5.7 and previous character sets?

mysql5.7 uses utf8mb4 character set instead of utf8

 

6. Will phper use only one framework?

It's not easy to find a job with only one framework. Generally, there are many frameworks. They are very similar. They are very simple

 

7. In web.php routing, the admin folder is introduced to route web.php?

include: include __DIR__.'/admin/web.php';
routes/web.php
routes/admin/web.php

 

 

8. What do the factories in the database folder in lavarel do?

With tinker, a large number of database data can be produced

Core steps:

D:\software\coding\php\phpstudy\PHPTutorial\WWW\legend3\legend3>php artisan tinker
Psy Shell v0.9.9 (PHP 7.2.1 — cli) by Justin Hileman
>>> factory(App\Model\Admin::class,3)->create();

Core code

$factory->define(\App\Model\Admin::class, function (Faker $faker) {
    static $password;
    return [
        'username' => $faker->name,
        'password' => $password ?: $password=bcrypt('admin888'), // secret
    ];
});

 

 

9. How to write the fields of the lavarel database migration?

You can change it according to your needs: for example, $table - > string ('username ') - > unique();
public function up()
{
  Schema::create('admins', function (Blueprint $table) {
      $table->increments('id');
      $table->timestamps();
      $table->string('username')->unique();
      $table->string('password');
  });
}

 

 

10. Create tables by the way when creating models?

PHP artican make: model model / admin - m: - m is the meaning of migration

 

 

 

2, Content in summary

[programming and development] latest laravel5+vue.js practice video playback mobile client + desktop multi platform project practice ゜゜゜゜゜゜つロロロ゜゜つつロロロ ~ - bilibili bili
https://www.bilibili.com/video/av41501829/?p=8

1. What do the factories in the database folder in lavarel do?

With tinker, a large number of database data can be produced

 

 

 

 

 

 

$factory->define(\App\Model\Admin::class, function (Faker $faker) {
    static $password;
    return [
        'username' => $faker->name,
        'password' => $password ?: $password=bcrypt('admin888'), // secret
    ];
});

 

Running PHP artican Tinker on the command line to enable tinker

Factory (App\Model\Admin::class, 3) - > create(); indicates that the tinker executes the factory of App\Model\Admin::class in factories in database
D:\software\coding\php\phpstudy\PHPTutorial\WWW\legend3\legend3>php artisan tinker
Psy Shell v0.9.9 (PHP 7.2.1 — cli) by Justin Hileman
>>> factory(App\Model\Admin::class,3)->create();
=> Illuminate\Database\Eloquent\Collection {#3006
     all: [
       App\Model\Admin {#3002
         username: "Jody Goldner",
         password: "$2y$10$ir53CAjYlmbSSvi64TJP8u9yRp.rhDJHkVwwDSXUECUYYZjosmVsW",
         updated_at: "2019-09-10 09:53:05",
         created_at: "2019-09-10 09:53:05",
         id: 1,
       },
       App\Model\Admin {#2997
         username: "Quincy Dietrich",
         password: "$2y$10$ir53CAjYlmbSSvi64TJP8u9yRp.rhDJHkVwwDSXUECUYYZjosmVsW",
         updated_at: "2019-09-10 09:53:15",
         created_at: "2019-09-10 09:53:15",
         id: 2,
       },
       App\Model\Admin {#2999
         username: "Janae Harber",
         password: "$2y$10$ir53CAjYlmbSSvi64TJP8u9yRp.rhDJHkVwwDSXUECUYYZjosmVsW",
         updated_at: "2019-09-10 09:53:15",
         created_at: "2019-09-10 09:53:15",
         id: 3,
       },
     ],
   }

 

 

 

These three records are generated in the database

Posted by GrayFox12 on Wed, 22 Apr 2020 05:00:51 -0700