Laravel 5.4 |如何使用 bootstrap fileinput 上传图片?

Laravel 5.4 | How to upload image using bootstrap fileinput?

我正在尝试使用 bootstrap-fileinput 插件在 laravel 项目中上传个人资料图片 这是视图

@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

objective 是将此图像上传到存储目录并将文件路径存储在数据库 table 中,但我不知道该怎么做,我正在通过 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');

}

请帮忙

使用 laravel 5.4 从请求中获取文件真的很容易。在您的情况下,您可以使用:

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

或:

$file = $request->file;

要存储文件,您可以使用 store 方法如下:

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

之后,您可以将返回的路径 ($path) 与其他客户详细信息一起存储在数据库中。

更多详情请访问此页面:Retrieving Uploaded Files and if you want to validate the file before processing it please see this: Validation Image Rule

希望对您有所帮助。祝你好运。