|
@@ -11,6 +11,7 @@ use Carbon\Carbon;
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
use App\Http\Requests;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
class AuthenticationController extends AdminController
|
|
|
{
|
|
@@ -79,23 +80,15 @@ class AuthenticationController extends AdminController
|
|
|
}
|
|
|
|
|
|
if($request->hasFile('id_card_image')){
|
|
|
- $savePath = storage_path('app/authentications');
|
|
|
$file = $request->file('id_card_image');
|
|
|
- $fileName = uniqid(str_random(8)).'.'.$file->getClientOriginalExtension();
|
|
|
- $target = $file->move($savePath,$fileName);
|
|
|
- if($target){
|
|
|
- $data['id_card_image'] = 'authentications-'.$fileName;
|
|
|
- }
|
|
|
+ $path = 'avatar/' . date("Ym/d", time());
|
|
|
+ $data['id_card_image'] = $this->upload_image($path, $file);
|
|
|
}
|
|
|
|
|
|
if($request->hasFile('skill_image')){
|
|
|
- $savePath = storage_path('app/authentications');
|
|
|
$file = $request->file('skill_image');
|
|
|
- $fileName = uniqid(str_random(8)).'.'.$file->getClientOriginalExtension();
|
|
|
- $target = $file->move($savePath,$fileName);
|
|
|
- if($target){
|
|
|
- $data['skill_image'] = 'authentications-'.$fileName;
|
|
|
- }
|
|
|
+ $path = 'avatar/' . date("Ym/d", time());
|
|
|
+ $data['skill_image'] = $this->upload_image($path, $file);
|
|
|
}
|
|
|
|
|
|
$authentication = Authentication::create($data);
|
|
@@ -107,6 +100,15 @@ class AuthenticationController extends AdminController
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function upload_image($path, $file, $drive = 'oss')
|
|
|
+ {
|
|
|
+ $disk = Storage::disk($drive);
|
|
|
+ //将图片上传到OSS中,并返回图片路径信息 值如:avatar/WsH9mBklpAQUBQB4mL.jpeg
|
|
|
+ $path = $disk->put($path, $file);
|
|
|
+ //由于图片不在本地,所以我们应该获取图片的完整路径,
|
|
|
+ //值如:https://test.oss-cn-hongkong.aliyuncs.com/avatar/8GdIcz1NaCZ.jpeg
|
|
|
+ return $disk->url($path);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Show the form for editing the specified resource.
|
|
@@ -151,23 +153,15 @@ class AuthenticationController extends AdminController
|
|
|
$data['recommend_at'] = Carbon::now();
|
|
|
}
|
|
|
if ($request->hasFile('id_card_image')) {
|
|
|
- $savePath = storage_path('app/authentications');
|
|
|
$file = $request->file('id_card_image');
|
|
|
- $fileName = uniqid(str_random(8)) . '.' . $file->getClientOriginalExtension();
|
|
|
- $target = $file->move($savePath, $fileName);
|
|
|
- if ($target) {
|
|
|
- $data['id_card_image'] = 'authentications-' . $fileName;
|
|
|
- }
|
|
|
+ $path = 'avatar/' . date("Ym/d", time());
|
|
|
+ $data['id_card_image'] = $this->upload_image($path, $file);
|
|
|
}
|
|
|
|
|
|
if ($request->hasFile('skill_image')) {
|
|
|
- $savePath = storage_path('app/authentications');
|
|
|
$file = $request->file('skill_image');
|
|
|
- $fileName = uniqid(str_random(8)) . '.' . $file->getClientOriginalExtension();
|
|
|
- $target = $file->move($savePath, $fileName);
|
|
|
- if ($target) {
|
|
|
- $data['skill_image'] = 'authentications-' . $fileName;
|
|
|
- }
|
|
|
+ $path = 'avatar/' . date("Ym/d", time());
|
|
|
+ $data['skill_image'] = $this->upload_image($path, $file);
|
|
|
}
|
|
|
|
|
|
$result = $authentication->update($data);
|