2017-04-03 90 views
0

我想使用自舉的FileInput插件在laravel項目 這裏上傳的輪廓圖像視圖Laravel 5.4 |如何使用bootstrap fileinput上傳圖片?

@section('content') 

<div class="fileinput fileinput-new" data-provides="fileinput"> 
    <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;"> 
      <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&amp;text=no+image" alt="" /> </div> 
       <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"> </div> 
        <div> 
         <span class="btn default btn-file"> 
           <span class="fileinput-new"> Select image </span> 
            <span class="fileinput-exists"> Change </span> 
              <input type="file" name="..."> </span> 
                <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput"> Remove </a> 
        </div> 
</div> 

@endsection 

的目標是將這一圖片上傳到存儲目錄並存儲在數據庫到文件的路徑表,但我不知道如何做到這一點,我通過POST提交表單到我的控制器中的商店方法。 下面是功能

public function store(Request $request) 
{ 
    // 
    $this->validate($request, [ 
    'first_name' => 'required', 
    'dob' => 'required', 
    'mobile_no' => 'unique:customers', 
    'adhar_no' => 'unique:customers', 

    ]); 

    $customer = new customer; 

    $customer->first_name = $request->first_name; 
    $customer->last_name = $request->last_name; 
    $customer->gender = $request->gender; 
    $customer->dob = $request->dob; 
    $customer->mobile_no = $request->mobile_no; 
    $customer->adhar_no = $request->adhar_no; 
    $customer->street = $request->street; 


    $customer->save(); 
    return redirect('home/customer'); 

} 

請幫

回答

1

隨着laravel 5.4它真的很容易得到請求的文件。你的情況,你可以使用:

$file = $request->file('file'); 

或者:

$file = $request->file; 

來存儲文件,你可以使用store方法如下:

$path = $request->file->store('the/path'); 

之後,你可以存儲返回數據庫中的路徑($ path)和其他客戶詳細信息。

欲瞭解更多詳情,請訪問此頁:Retrieving Uploaded Files,如果你想處理它,請參閱此之前驗證文件:Validation Image Rule

我希望這會幫助你。祝你好運。