2 回答
TA贡献1836条经验 获得超5个赞
请使用以下方法添加默认设置空值
在模型中设置 屏幕截图
protected $attributes = array(
'image' => '',
);
或
if($request->hasFile('image')){
$fileNameExt = $request->file('image')->getClientOriginalName();
$fileName = pathinfo($fileNameExt, PATHINFO_FILENAME);
$fileExt = $request->file('image')->getClientOriginalExtension();
$fileNameToStore = $fileName.'.'.$fileExt;
$pathToStore = $request->image->storeAs('public/uploads/screenshots', $request->image->getClientOriginalName());
$screenshots->image = $fileNameToStore;
$screenshots->save();
}else{
$screenshots->image = '';
}
TA贡献1802条经验 获得超10个赞
在“屏幕截图”中.php模型定义属性/属性的默认值(如果未按如下方式设置)
class Screenshot extends Model { protected $attributes = ['image' => null]; }
- 2 回答
- 0 关注
- 115 浏览
添加回答
举报