Laravel Faker - create 和 make 有什么区别
Laravel Faker - What's the difference between create and make
我有以下代码:
$this->actingAs(factory('App\User')->create());
$thread = factory('App\Thread')->make();
create() 和 make() 之间有什么区别?为什么 Laravel 文档的辅助函数页面中没有列出它?谢谢! :)
create
持久保存到数据库,而 make
只是创建模型的一个新实例。
The create
method not only creates the model instances but also saves
them to the database using Eloquent's save method
https://laravel.com/docs/5.4/database-testing#using-factories
如果您想查看 make 和 create 之间的源代码差异,可以在 src/Illuminate/Database/Eloquent/FactoryBuilder.php
中查看它们
Laravel create method is created the model instance and save data in the database.
Make function has created the instance of the class.
我有以下代码:
$this->actingAs(factory('App\User')->create());
$thread = factory('App\Thread')->make();
create() 和 make() 之间有什么区别?为什么 Laravel 文档的辅助函数页面中没有列出它?谢谢! :)
create
持久保存到数据库,而 make
只是创建模型的一个新实例。
The
create
method not only creates the model instances but also saves them to the database using Eloquent's save method
https://laravel.com/docs/5.4/database-testing#using-factories
如果您想查看 make 和 create 之间的源代码差异,可以在 src/Illuminate/Database/Eloquent/FactoryBuilder.php
Laravel create method is created the model instance and save data in the database.
Make function has created the instance of the class.