2016-11-21 83 views
0

Laravel 5.2中的圖像顯示爲我的Users表結構,黃色標記表示當我通過Laravel默認身份驗證註冊時,這些行包含數據。現在我想更新空行。我已創建profile.blade.php使用Post方法和userController進行編碼:Laravel用戶表更新

<?php 

namespace App\Http\Controllers; 

use App\User; 
use Illuminate\Http\Request; 

use App\Http\Requests; 
use Auth; 
use Image; 

class UsersController extends Controller 
{ 
    public function getsignup() 
    { 
     return view('edit_profile', array('user' => Auth::user())); 
    } 

    public function postsignup(Request $request) 
    { 
     //dd($request->all());   

     if($request->hasFile('img')){ 
      $img = $request->file('img'); 
      $file_name = time() . '.' . $img->getClientOriginalExtension(); 
      Image::make($img)->resize(300, 300)->save(public_path('/uploads/images/' . $file_name)); 

     } 
     $user = Auth::User(); 
     $user->img =$file_name; 
     $user->city = 'city'; 
     $user->country = 'country'; 
     $user->company_name = 'comapany_name'; 
     $user->street_name = 'street_name'; 
     $user->apartment = 'apartment'; 
     $user->village = 'village'; 
     $user->city = 'city'; 
     $user->postal_code = 'postal_code'; 
     $user->post_office = 'post_office'; 
     $user->nid = 'nid'; 
     $user->phone = 'phone'; 

     $user->save(); 
     return back()->with('message', 'Successfully Registered!'); 
    }  
    } 

enter image description here 但其僅採取這種值,如「城市」,「COMPANY_NAME」等。作爲我提供第二圖像。我被困。我是Laravel的新人。我希望你對我有一個解決方案。提前致謝。

enter image description here

回答

0

爲什麼if條件裏面的字段更新? 這樣,如果圖像上傳

只會更新試試這個

public function postsignup(Request $request) 
    { 
     //dd($request->all()); 


     if($request->hasFile('img')){ 
      $img = $request->file('img'); 
      $file_name = time() . '.' . $img->getClientOriginalExtension(); 
      Image::make($img)->resize(300, 300)->save(public_path('/uploads/images/' . $file_name)); 
      $user->img =$file_name; 
      } 


     $user = Auth::User(); 
     $user->city = $s; 
     $user->country = 'country'; 
     $user->company_name = 'comapany_name'; 
     $user->street_name = 'street_name'; 
     $user->apartment = 'apartment'; 
     $user->village = 'village'; 
     $user->city = 'city'; 
     $user->img = isset($user->img)? $user->img : ''; 
     $user->postal_code = 'postal_code'; 
     $user->post_office = 'post_office'; 
     $user->nid = 'nid'; 
     $user->phone = ' 

     $user->save(); 
     return back()->with('message', 'Successfully Registered!'); 
    } 
+0

嗨! @Sherif。感謝您的重播。我運行你的代碼,但它說'img'爲空或空。所以我改變一些小代碼,給我的表格另一個屏幕截圖。你會看到這一點。謝謝Agai –

+0

'$ file_name'不能被設置,你需要允許圖像在數據庫中爲空,如果它不是必需的 – Sherif

0

這完美的作品:

public function postsignup(Request $request) 
    { 
     //dd($request->all()); 


     if($request->hasFile('img')){ 
      $img = $request->file('img'); 
      $file_name = time() . '.' . $img->getClientOriginalExtension(); 
      Image::make($img)->resize(300, 300)->save(public_path('/uploads/images/' . $file_name)); 

     } 
     $user = Auth::User(); 
     $user->img =$file_name; 
     $user->city = $request->city; 
     $user->country = $request->country; 
     $user->company_name = $request->comapany_name; 
     $user->street_name = $request->street_name; 
     $user->apartment = $request->apartment; 
     $user->village = $request->village; 
     $user->postal_code =$request ->postal_code; 
     $user->post_office =$request->post_office; 
     $user->nid = $request->nid; 
     $user->phone = $request->phone; 

     $user->save(); 
     return back()->with('message', 'Successfully Registered!'); 
    }