我正在使用Restful API,当我想在数据库中植入假数据时,出现异常消息。
php artisan migrate:fresh
php artisan db:seed
我使用迁移和控制器进行建模:
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->text('content');
$table->dateTime('date_written');
$table->String('feature_image')->unllable();
$table->integer('votes_up')->unllable();
$table->integer('votes_down')->unllable();
// TelationShipe.
$table->integer('user_id');
$table->integer('category_id');
$table->timestamps();
});
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $fillable = [
'title' , 'content' , 'date_written' ,
'feature_image' , 'votes_up' ,
'votes_down' , 'user_id' ,
'category_id'
];
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostController extends Controller
{
//
}
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
factory(\App\Post::class , 100 )->create();
}
}
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\User;
use Faker\Generator as Faker;
use Illuminate\Support\Str;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/
$factory->define(User::class, function (Faker $faker) {
return [
'title' => $faker->title,
'content' => $faker->text(400),
'date_written' => $faker->new(),
'feature_image' => $faker->imageUrl(),
'votes_up' => $faker->numberBetween(1 , 100),
'votes_down' => $faker->numberBetween(1 , 100),
'user_id' => $faker->numberBetween(1 , 15),
'category_id' => $faker->numberBetween(1 , 15),
];
});
InvalidArgumentException:
处的未知格式化程序“ new” ~/vendor/fzaninotto/faker/src/Faker/Generator.php:242
238|
239| return $this->formatters[$formatter];
240| }
241| }
242| throw new \InvalidArgumentException(sprintf('Unknown formatter "%s"', $formatter));
243| }
244|
245| /**
* Replaces tokens ('{{ tokenName }}') with the result
* from the token method call
*/
Exception trace:
1 Faker\Generator::getFormatter("new")
~/vendor/fzaninotto/faker/src/Faker/Generator.php:222
2 Faker\Generator::format("new", [])
~/vendor/fzaninotto/faker/src/Faker/Generator.php:279
Please use the argument -v to see more details.
答案 0 :(得分:1)
更改此行
来自
export const updateDashboardCount = (id, childName) =>
db.ref('dashboard/' + id).child(childName).transaction((data) => {
if(data===null)
return data;
console.log('data is', data);
});
收件人
'date_written' => $faker->new(),
now()将返回数据库迁移所需的当前时间的Carbon实例
在造假者生成器上没有名为
'date_written' => now(),
的函数
希望这会有所帮助