您现在的位置是:主页 > news > 可以自己做网站不/厦门网站优化公司

可以自己做网站不/厦门网站优化公司

admin2025/5/16 17:57:35news

简介可以自己做网站不,厦门网站优化公司,男女做暖暖免费网站,企业代理注册公司在命令行从进入到 laravel 文件目录创建注入文件在命令行执行php artisan make:migration postphp artisan make:migration post书写数据库注入代码在 database/migtations 目录下找到 201x_xx_xx_xxxxxx_post.php 文件Paste_Image.png打开后写好注入代码:use Illuminate\Datab…

可以自己做网站不,厦门网站优化公司,男女做暖暖免费网站,企业代理注册公司在命令行从进入到 laravel 文件目录创建注入文件在命令行执行php artisan make:migration postphp artisan make:migration post书写数据库注入代码在 database/migtations 目录下找到 201x_xx_xx_xxxxxx_post.php 文件Paste_Image.png打开后写好注入代码:use Illuminate\Datab…

在命令行从进入到 laravel 文件目录

创建注入文件

在命令行执行

php artisan make:migration post

ca2d595b4003dbbd9a8ba0c2462d4e5b.png

php artisan make:migration post

书写数据库注入代码

在 database/migtations 目录下找到 201x_xx_xx_xxxxxx_post.php 文件

a234b413cbf5

Paste_Image.png

打开后写好注入代码:

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Database\Migrations\Migration;

class Post extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::create('posts', function (Blueprint $table) {

$table->increments('id');

$table->string('title');

$table->string('text');

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

//

Schema::drop('posts');

}

}

运行迁移

命令行执行

php artisan migrate

a234b413cbf5

Paste_Image.png

执行后在数据库查看结果

b5f6124200ac7b7641c52a750e59be8e.png

database

编写数据填充

命令行执行

php artisan make:seeder postSeeder

a234b413cbf5

Paste_Image.png

执行后在 database/seeds 目录下找到 postSeeder.php

a234b413cbf5

Paste_Image.png

对照数据库表结构添加代码:

use Illuminate\Database\Seeder;

class postSeeder extends Seeder

{

/**

* Run the database seeds.

*

* @return void

*/

public function run()

{

//

$data = [];

// 循环

for ($i = 0; $i < 20; $i++){

$tmp = [];

$tmp['title'] = 'Title-' . str_random(6) .'-'. $i;

$tmp['text'] = 'Content-' . str_random(100) .'-'. $i;

$tmp['created_at'] = date('Y-m-d H:i:s');

$tmp['updated_at'] = date('Y-m-d H:i:s');

$data[] = $tmp;

}

// 插入

DB::table('posts')->insert($data);

}

}

填充

找到和 postSeederphp 同目录下的 DatabaseSeeder.php

在 run 函数下添加我们的 seeder 类

a234b413cbf5

Paste_Image.png

public function run()

{

Model::unguard();

// $this->call(UserTableSeeder::class);

// 添加我们的 postSeeder 类

$this->call(postSeeder::class);

Model::reguard();

}

命令行执行

php artisan migrate:refresh --seed

00a7a13bcc1ce4a0b23cc23c8b3b0acf.png

php artisan migrate:refresh --seed

在数据库中查看

a72213e275df41a07e57f0073195a85f.png

Seeded: postSeeder

大功告成!