正如我在标题中所述,可以在模型中完成吗?
if ($request->hasFile('file')) {
$file= $request->file('file');
$path= Storage::disk('public')->putFile('/', new
File($file));
$dB->path = $path;
$db->save();
}
答案 0 :(得分:1)
在您的模型中:
public function insertFile($file) {
if($this->path) {
Storage::disk('public')->delete($this->path)
}
$path= Storage::disk('public')->putFile('/', new File($file));
$this->path = $path;
$this->save();
}
在您的控制器中:
if ($request->hasFile('file')) {
$db->insertFile($request->file('file');
}