Kaynağa Gözat

页面显示问题

任敬轩 4 yıl önce
ebeveyn
işleme
a5abc3f032

+ 18 - 24
app/Http/Controllers/Admin/AuthenticationController.php

@@ -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);

+ 1 - 1
app/Models/Authentication.php

@@ -82,7 +82,7 @@ class Authentication extends Model
             ->orderBy('user_data.answers', 'DESC')
             ->orderBy('user_data.articles', 'DESC')
             ->orderBy('authentications.recommend_at', 'DESC')
-            ->select('authentications.user_id', 'authentications.real_name', 'authentications.title', 'user_data.coins',
+            ->select('authentications.user_id', 'authentications.real_name','authentications.id_card_image', 'authentications.title', 'user_data.coins',
                 'user_data.credits', 'user_data.followers', 'user_data.supports', 'user_data.answers',
                 'user_data.articles', 'user_data.authentication_status')
             ->take($size)->get();

+ 5 - 6
resources/views/admin/authentication/create.blade.php

@@ -16,6 +16,10 @@
                                 <input type="text" name="user_id" class="form-control " placeholder="申请认证的用户UID" value="{{ old('user_id','') }}">
                                 @if($errors->has('user_id')) <p class="help-block">{{ $errors->first('user_id') }}</p> @endif
                             </div>
+                            <div class="form-group">
+                                <label>头像</label>
+                                <input type="file" name="id_card_image" />
+                            </div>
                             <div class="form-group @if($errors->has('real_name')) has-error @endif">
                                 <label>真实姓名</label>
                                 <input type="text" name="real_name" class="form-control " placeholder="真实姓名" value="{{ old('real_name','') }}">
@@ -71,11 +75,6 @@
                             </div>
 
                             <div class="form-group">
-                                <label>身份证正面图片</label>
-                                <input type="file" name="id_card_image" />
-                            </div>
-
-                            <div class="form-group">
                                 <label>所属分类</label>
                                 <select name="category_id" class="form-control">
                                     <option value="0">选择分类</option>
@@ -144,4 +143,4 @@
             });
         });
     </script>
-@endsection
+@endsection

+ 11 - 13
resources/views/admin/authentication/edit.blade.php

@@ -12,7 +12,15 @@
                         <input name="_method" type="hidden" value="PUT">
                         <input type="hidden" name="_token" value="{{ csrf_token() }}">
                         <div class="box-body">
-
+                            <div class="form-group">
+                                <label>头像</label>
+                                <input type="file" name="id_card_image" />
+                                @if($authentication->id_card_image)
+                                    <div style="margin-top: 10px;">
+                                        <img class="img-responsive" width="400" src="{{ $authentication->id_card_image }}" style="height:100px;width:auto;"/>
+                                    </div>
+                                @endif
+                            </div>
                             <div class="form-group @if($errors->has('real_name')) has-error @endif">
                                 <label>真实姓名</label>
                                 <input type="text" name="real_name" class="form-control " placeholder="真实姓名" value="{{ old('real_name',$authentication->real_name) }}">
@@ -71,16 +79,6 @@
                             </div>
 
                             <div class="form-group">
-                                <label>身份证正面图片</label>
-                                <input type="file" name="id_card_image" />
-                                @if($authentication->id_card_image)
-                                <div style="margin-top: 10px;">
-                                    <img class="img-responsive" width="400" src="{{ route('website.image.show',['image_name'=>$authentication->id_card_image]) }}" />
-                                </div>
-                                @endif
-                            </div>
-
-                            <div class="form-group">
                                 <label>所属分类</label>
                                 <select name="category_id" class="form-control">
                                     <option value="0">选择分类</option>
@@ -99,7 +97,7 @@
                                 <input type="file" name="skill_image" />
                                 @if($authentication->skill_image)
                                     <div style="margin-top: 10px;">
-                                        <img class="img-responsive" width="400" src="{{ route('website.image.show',['image_name'=>$authentication->skill_image]) }}" />
+                                        <img class="img-responsive" width="400" src="{{ $authentication->skill_image }}" style="height:100px;width:auto;"/>
                                     </div>
                                 @endif
                             </div>
@@ -154,4 +152,4 @@
             });
         });
     </script>
-@endsection
+@endsection

+ 1 - 1
resources/views/themes/default/home/index.blade.php

@@ -86,7 +86,7 @@
                         @foreach($hotExperts as $expert)
                             <section class="col-sm-6 col-md-3">
                                 <div class="thumbnail">
-                                    <a href="{{ route('auth.space.index',['user_id'=>$expert->user_id]) }}" target="_blank"><img class="avatar-128" src="{{ $expert->qrcode }}" alt="{{ $expert->real_name }}"></a>
+                                    <a href="{{ route('auth.space.index',['user_id'=>$expert->user_id]) }}" target="_blank"><img class="avatar-128" src="{{ $expert->id_card_image }}" alt="{{ $expert->real_name }}" style="width:75px;height:75px;"></a>
                                     <div class="caption">
                                         <h4 class="text-center"><a href="{{ route('auth.space.index',['user_id'=>$expert->user_id]) }}" title="{{ $expert->real_name }}">{{ str_limit($expert->real_name,10,'') }}</a></h4>
                                         <p class="text-muted text-center" title="{{ $expert->title }}">{{ str_limit($expert->title,16,'') }}&nbsp;</p>