我想使用laravel中的Eloquent中的create方法插入数据。这个方法默认会返回model对象,但是如何得知插入数据是否成功呢?之前的框架都会返回一个bool类型的。
create方法代码如下:
public static function create(array $attributes = [])
{
$model = new static($attributes);
$model->save();
return $model;
}
你可以采用另一个方法
save()
,具体使用方法见下方成功的话是返回一个model对象的,是不是一定会成功呢?