2016-12-17 70 views
0

返回失敗了,我不知道爲什麼,它不上傳IMGLaravel - 慣於上傳圖片到數據庫

public function updatelogo(Request $request) 
{ 
    if($request->hasFile('logo')){ 
     $logo = $request->file('logo'); 
     $filename = time() . '.' . $logo->getClientOriginalExtension(); 
     Image::make($logo)->resize(50, 50)->save(public_path('/images/games/' . $filename)); 

     $game_id = $request->input('game'); 

     $games = Games::where('id', '=', $game_id)->get(); 
     $games->logourl = $filename; 
     $games->save(); 
     return redirect()->back()->with("status", "Succesfully edited!"); 
     } 
     return redirect()->back()->with("status", "FAILED!"); 
} 

前端:

<form action="{{ url('/admin/sitesettings/games/edit/logo') }}" method="POST"> 
          <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
          <div class="form-group"> 
           <label for="logo" class="col-md-4 control-label">Logo</label> 
           <small>Upload a logo</small> 
           <select name="game" id="game"> 
           @foreach($games as $game) 
            <option value="{{$game->id}}">{{$game->name}}</option> 
           @endforeach 
           </select> 
           <div> 
            <input id="logo" type="file" class="form-control" name="logo"> 
           </div> 
          </div> 
         </div> 
         <button type="submit" class="btn btn-primary">Save changes</button> 
        </form> 

你能幫助我呢?我不知道爲什麼它不會工作tho

回答

0

它看起來有什麼問題,你沒有上傳圖像使用logo,請粘貼你的前端代碼,所以我可以幫你。

+0

我將它添加到頂端@wanghanlin – Robinvm