laravel 社区 使用ModelFactory 生产测试数据 artisan 建表
来源:互联网 发布:python 3程序开发指南 编辑:程序博客网 时间:2024/05/01 03:06
php artisan make:migration create_discussions_table –create=discussions
public function up()
{
Schema::create(‘discussions’, function (Blueprint table) {table->increments(‘id’);
});
}
public function up()
{
Schema::create(‘users’, function (Blueprint table) {table->increments(‘id’);
});
}
迁移表
php artisan migtate
在 User.php
protected $fillable = [‘name’, ‘email’, ‘password’,’avatar’];
在Discussion.php
protected $fillable = [‘title’, ‘body’, ‘user_id’,’last_user_id’];
在Model Factories
/*
|————————————————————————–
*/
return [
‘name’ =>
‘avatar’ => $faker->imageUrl(256,256),
‘password’ => str_random(10),
‘remember_token’ => str_random(10),
];
});
通过使用 Laravel artisan 内建的 php artisan tinker , 我们可以很方便的看到数据库中的数据并且执行各种想要的操作。
创建30个user
D:\xampp\htdocs\laravelB\laravel>php artisan tinker
Psy Shell v0.7.2 (PHP 5.6.15 鈥?cli) by Justin Hileman
namespace App;
=> null
factory(User::class,30)->create();
得到等等 => Illuminate\Database\Eloquent\Collection {#699
all: [
App\User {#708
name: “Mrs. Cathy Gibson II”,
email: “gina.monahan@hotmail.com”,
avatar: “http://lorempixel.com/256/256/?79243“,
updated_at: “2016-08-07 13:08:29”,
created_at: “2016-08-07 13:08:29”,
id: 1,
},
App\User {#707
name: “Angela Wilderman”,
email: “rhane@huel.biz”,
avatar: “http://lorempixel.com/256/256/?12201“,
updated_at: “2016-08-07 13:08:29”,
created_at: “2016-08-07 13:08:29”,
id: 2,
},
在Model Factories
$user_ids = \App\User::lists(‘id’)->toArray(); /获得user_id 并转为 array/
return [
‘title’ =>
‘user_id’ =>
‘last_user_id’ =>
];
});
- laravel 社区 使用ModelFactory 生产测试数据 artisan 建表
- laravel artisan工具的使用
- laravel artisan
- laravel 使用artisan命令新增数据库字段
- 使用laravel 的artisan快速创建表
- Laravel artisan 命令工具
- Laravel artisan 命令工具
- laravel php artisan 错误
- Laravel artisan常用命令集锦
- Laravel artisan 命令工具
- Laravel artisan 命令工具
- Laravel Artisan 控制台
- laravel artisan常用命令
- Laravel artisan 命令工具
- Laravel artisan常用命令集锦
- 使用 Laravel 数据填充生成 中文 测试数据
- laravel 使用测试工厂Factory添加测试数据
- laravel框架学习(三)win下php artisan tinker 测试数据时,无法运行报错的解决方法
- Android Studio 错误 com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
- JavaMail--基础类详解
- JDBC基础应用(数据库增删改查)
- 在VS2015中用C++创建MFC规则动态库DLL
- dl4j基本环境搭建(win7+64位jdk1.8+IDEA)
- laravel 社区 使用ModelFactory 生产测试数据 artisan 建表
- UVALive-7392 - Bundles of Joy【树型DP】【深搜】【好题】
- "两地三中心"的容灾解决方案
- Effective Modern C++ 条款2 理解auto类型推断
- K sum算法
- 占位符
- java面试题训练0807_字符串逆转及回文
- Android UI(CheckBox)详解
- java学习之路 之 高级类特性1-instanceof操作符、对象类型转换(造型)