//Laravel5.3 \Illuminate\Database\Eloquent\Model
public static function create(array $attributes = [])
{
$model = new static($attributes);
$model->save();
return $model;
}
public function save(array $options = [])
{
...
// If the "saving" event returns false we'll bail out of the save and return
// false, indicating that the save failed. This provides a chance for any
// listeners to cancel save operations if validations fail or whatever.
if ($this->fireModelEvent('saving') === false) {
return false;
}
...
}
laravel create 操作成功就会返回一个model
看源码知道如果save失败,返回
false;如果成功,返回model。谢谢邀请。create方法应该有返回值的。打印输出看看
创建成功 会返回model 不成功 会返回null 可以直接 if(!result) 判断