我本来的代码是使用了firstOrCreate ,但是实际create才会调用到
模型文件
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'shop_id' => 'integer', 'question_id' => 'integer', 'book_category_id' => 'integer', 'user_id' => 'integer', 'book_id' => 'integer','images'=>'array'];
使用地方
UserQuestionFeedback::create([ 'book_id' => $book_id, 'book_category_id' => $bookInfo['categories_id'], 'user_id' => $user['id'], 'question_id' => $question_id, 'phone' => $phone, 'content' => $content, 'images' => $images, 'shop_id' => $this->shop_id ]);
create跟firstOrcreate源码
public function create(array $attributes = []) { return tap($this->newModelInstance($attributes), function ($instance) { $instance->save(); }); } public function firstOrCreate(array $attributes, array $values = []) { if (! is_null($instance = $this->where($attributes)->first())) { return $instance; } return tap($this->newModelInstance($attributes + $values), function ($instance) { $instance->save(); }); }
这个问题就很明显了
标签:instance,Hyperf,插入,json,book,attributes,integer,array,id From: https://www.cnblogs.com/sdfgdrg/p/18302962