public function getCompanyCoverInfo($company_id) { $company_cover = Company::where('id', '=', $company_id)->first(); $file_info = File::where('id', '=', $company_cover->company_cover)->first()->toArray(); return $file_info; }
public function updateUploadedCompanyCover(FileService $file, $user_id, $company_id) { try { $cover = Request::file('cover'); $file_info = $file->getCompanyCoverInfo($company_id); $previous_file_name = explode('.', $file_info['new_file_name']); $new_file_name = md5($previous_file_name[0] . '' . date('Y-m-d') . '' . uniqid()) . '.' . $previous_file_name[1]; $move_status = $cover->move(public_path('files'), $new_file_name); if ($move_status) { $update_file = File::find($file_info['id']); $update_file->new_file_name = $new_file_name; $update_file->save(); return $this->json_response->success(env('FILE_URL') . '/' . $new_file_name); } return $this->json_response->error(); } catch (Exception $e) { return $this->json_response->error(['error' => $e->getMessage()]); } }