我在UploadController
中有此功能,用于取消上传,我正在努力改进它。
这个"File::delete..block"
在我的申请中存在两次。例如,从控制器中排除这个块是否有意义?如果是,我应该使用什么,Repository
,Service Provider
或Event
?
public function postDelete(Request $request)
{
$filename = $request->input('filename');
$upload = Upload::where('filename',$filename)->where('accepted',0)->firstOrFail();
File::delete('img/uploads/'.$filename.'_o.jpg');
File::delete('img/uploads/'.$filename.'.jpg');
File::delete('img/uploads/'.$filename.'_zoom.jpg');
File::delete('img/uploads/'.$filename.'_tn.jpg');
File::delete('img/uploads/'.$filename.'_250.jpg');
File::delete('img/uploads/'.$filename.'_50.jpg');
$upload->delete();
Cache::forget('waiting_uploads');
$msg = 'upload has been deleted';
Mail::to('xyz@xxx.tld')->send(new TextMail($msg));
return redirect('upload');
}
答案 0 :(得分:1)
我会把它放在一个调用存储库的服务中。这样,您的控制器就不会与数据层对象进行交互,所有内容都会干净利落地分开。