目前,我使用Laravel Passport API
我有此代码,并且工作正常。
//Saves file to public folder
$dateTime = date('Ymd_His');
$file = $request->file('file');
$fileName = $dateTime . '-' . $file->getClientOriginalName();
$savePath = public_path('/upload/img/');
$file->move($savePath, $fileName);
//This saves the current file path of image to mytable
$ActivityLog = new ActivityLogImg;
$ActivityLog->actCode = $activity_code;
$ActivityLog->projCode = $request->projCode;
$ActivityLog->attachment = "/upload/img/".$fileName;
$ActivityLog->type = "IMAGE";
$ActivityLog->deleted = 0;
$ActivityLog->created_by_id = Auth::user()->company_id;
$ActivityLog->created_by_name = Auth::user()->name;
$ActivityLog->created_at = now();
$ActivityLog->updated_at = now();
$ActivityLog->save();
return response([
"status"=>"ok",
"message"=>"Activity successfully submitted!"
]);
我有这个邮递员的要求来测试api,它工作正常
答案 0 :(得分:1)
是的,可以使用您的代码完成此操作
在邮递员通行证名称中多次使用file[]
foreach($request->file('file') as $file){
$dateTime = date('Ymd_His');
$fileName = $dateTime . '-' . $file->getClientOriginalName();
$savePath = public_path('/upload/img/');
$file->move($savePath, $fileName);
//This saves the current file path of image to mytable
$ActivityLog = new ActivityLogImg;
$ActivityLog->actCode = $activity_code;
$ActivityLog->projCode = $request->projCode;
$ActivityLog->attachment = "/upload/img/".$fileName;
$ActivityLog->type = "IMAGE";
$ActivityLog->deleted = 0;
$ActivityLog->created_by_id = Auth::user()->company_id;
$ActivityLog->created_by_name = Auth::user()->name;
$ActivityLog->created_at = now();
$ActivityLog->updated_at = now();
$ActivityLog->save();
}
return response([
"status"=>"ok",
"message"=>"Activity successfully submitted!"
]);