2017-02-10 44 views
0

我正在上传文件并将其保存在本地存储中。这些文件存储在与特定用户相关的数据库中。当我返回最后保存的用户。我正确回答了其他细节。但不是文件路径。我得到的文件作为响应Laravel返回上传的文件而不是它的路径

$file = $request->file('resume'); 
$profile_id = $request['profile_id']; 
$original_name = $_FILES['resume']['name'];     
$resume_new_name = str_random(). '.' . $file->getClientOriginalExtension(); 
$new_file = $request->file('resume')->move('resources/assets/resumes',$resume_new_name); 
$candidate_info['resume'] = $new_file; 
$candidate = new candidate(); 
    if (empty($candidate_info['name'])) { 
      $candidate_info['name'] = $candidate_info['email']; 
    } 
     $candidate->name = $candidate_info['name']; 
     $candidate->phone = $candidate_info['phone']; 
     $candidate->email = $candidate_info['email']; 
     $candidate->resume = $candidate_info['resume']; 
     $candidate->client_id = \Auth::user()->id; 
     $candidate->status = "new"; 
     $candidate->profile_id = $profile_id; 
     $candidate->save(); 
     return response()->json(['msg' => $candidate]); 

在数据库列'resume'中存储路径。但在json响应中,它会发送整个文件而不是路径。如何发送,而不是发送整个文件

回答

0

只返回一个列的值路径:

return response()->json(['msg' => $candidate->resume]); 
0

而不是使用移动使用

$new_file = $request->file('resume')->store('resources/assets/resumes',$resume_new_name); 
相关问题