Php Laravel中的文件上载问题

Php Laravel中的文件上载问题,php,file,laravel,upload,Php,File,Laravel,Upload,我有一个简单的表单,其中有一个文件上传输入,它不会转储文件输入值 这是我的表格代码: <!-- Modal --> <div class="modal fade" id="app-form" tabindex="-1" role="dialog" aria-labelledby="app-form-label"> <div class="modal-dialog" role="document">

我有一个简单的表单,其中有一个文件上传输入,它不会转储文件输入值

这是我的表格代码:

<!-- Modal -->
        <div class="modal fade" id="app-form" tabindex="-1" role="dialog" aria-labelledby="app-form-label">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="app-form-label">Ședință foto boudoir!</h4>
                    </div>

                    {!! Form::open(['url'=>'','method'=>'POST', 'files'=>true, 'id' => 'model-form']) !!}
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-xs-12 col-sm-6">
                                <div class="form-group{{ $errors->has('first_name') ? ' has-error' : '' }}">
                                    {!! Form::label('first_name', 'Nume') !!}
                                    {!! Form::text('first_name', '', ['class' => 'form-control']) !!}
                                    @if ($errors->has('first_name'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('first_name') }}</strong>
                                         </span>
                                    @endif
                                </div>
                            </div>

                            <div class="col-xs-12 col-sm-6">
                                <div class="form-group{{ $errors->has('last_name') ? ' has-error' : '' }}">
                                    {!! Form::label('last_name', 'Prenume') !!}
                                    {!! Form::text('last_name', '', ['class' => 'form-control']) !!}
                                    @if ($errors->has('last_name'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('last_name') }}</strong>
                                         </span>
                                    @endif
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xs-12 col-sm-6">
                                <div class="form-group{{ $errors->has('age') ? ' has-error' : '' }}">
                                    {!! Form::label('age', 'Vârsta') !!}
                                    {!! Form::text('age', '', ['class' => 'form-control']) !!}
                                    @if ($errors->has('age'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('age') }}</strong>
                                         </span>
                                    @endif
                                </div>
                            </div>

                            <div class="col-xs-12 col-sm-6">
                                <div class="form-group{{ $errors->has('sex') ? ' has-error' : '' }}">
                                    {!! Form::label('sex', 'Vârsta') !!}
                                    {!! Form::select('sex', ['M' => 'Masculin', 'F' => 'Feminin'], null, ['class' =>
                                    'form-control',
                                    'placeholder' =>
                        '-- Selectează --']) !!}
                                    @if ($errors->has('sex'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('sex') }}</strong>
                                         </span>
                                    @endif
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xs-12 col-sm-6">
                                <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                                    {!! Form::label('email', 'Email') !!}
                                    {!! Form::email('email', '', ['class' => 'form-control']) !!}
                                    @if ($errors->has('email'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('email') }}</strong>
                                         </span>
                                    @endif
                                </div>
                            </div>

                            <div class="col-xs-12 col-sm-6">
                                <div class="form-group{{ $errors->has('phone') ? ' has-error' : '' }}">
                                    {!! Form::label('phone', 'Telefon') !!}
                                    {!! Form::text('phone', '', ['class' => 'form-control']) !!}
                                    @if ($errors->has('phone'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('phone') }}</strong>
                                         </span>
                                    @endif
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xs-12">
                                <div class="form-group{{ $errors->has('details') ? ' has-error' : '' }}">
                                    {!! Form::label('details', 'Detalii') !!}
                                    {!! Form::textarea('details', '', ['class' => 'form-control', 'rows' => 10]) !!}
                                    @if ($errors->has('details'))
                                        <span class="help-block">
                                            <strong>{{ $errors->first('details') }}</strong>
                                         </span>
                                    @endif
                                </div>
                            </div>
                        </div>

                        {!! Form::label('image', 'Fotografii Reprezentative') !!}
                        {!! Form::file('image') !!}
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-warning card-2">Trimite Datele</button>
                    </div>
                    {!! Form::close() !!}
                </div>
            </div>
        </div>
        <!-- /End Modal -->

&时代;
爱丁·福托闺房!
{!!Form::open(['url'=>'','method'=>'POST','files'=>true,'id'=>'model Form'])
{!!Form::label('first_name','Nume')
{!!Form::text('first_name','',['class'=>'Form control'])
@如果($errors->has('first_name'))
{{$errors->first('first_name')}
@恩迪夫
{!!Form::label('last_name','Prenume')
{!!Form::text('last_name','',['class'=>'Form control'])
@如果($errors->has('last_name'))
{{$errors->first('last_name')}
@恩迪夫
{!!Form::label('age','V–rsta')
{!!Form::text('age','',['class'=>'Form control'])
@如果($errors->has('age'))
{{$errors->first('age')}
@恩迪夫
{!!Form::label('sex','V–rsta')
{!!Form::select('sex',['M'=>'mangian','F'=>'Feminin',null,['class'=>
“窗体控件”,
“占位符”=>
“--Selectează--”])
@如果($errors->has('sex'))
{{$errors->first('sex')}
@恩迪夫
{!!表单::标签('email','email')
{!!Form::email('email','',['class'=>'Form control'])
@如果($errors->has('email'))
{{$errors->first('email')}
@恩迪夫
{!!表单::标签('phone','Telefon')
{!!Form::text('phone','',['class'=>'Form control'])
@如果($errors->has('phone'))
{{$errors->first('phone')}
@恩迪夫
{!!Form::label('details','Detalii')
{!!Form::textarea('details','',['class'=>'表单控件','rows'=>10])
@如果($errors->has('details'))
{{$errors->first('details')}
@恩迪夫
{!!Form::label('image','Fotografii Reprezentative')
{!!Form::file('image')!!}
三色枣椰
{!!Form::close()!!}
我使用ajax来完成这篇文章,代码如下:

<script>
    (function () {
        $('#model-form').submit(function (e) {
            e.preventDefault();
            $.ajax({
                type: 'POST',
                url: 'store',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: new FormData(this),
                contentType: false,
                cache: false,
                processData:false,
                success: function (response) {
                    console.log($('#image').val());
                }
            });
        });
    })();
</script>

(功能(){
$(“#模型表格”)。提交(功能(e){
e、 预防默认值();
$.ajax({
键入:“POST”,
url:'商店',
标题:{
'X-CSRF-TOKEN':$('meta[name=“CSRF-TOKEN”]).attr('content'))
},
数据:新表单数据(本),
contentType:false,
cache:false,
processData:false,
成功:功能(响应){
log($('#image').val());
}
});
});
})();
现在不要问我为什么要在ajax中设置csrf令牌头
<form action="" method="POST" enctype="multipart/form-data">
</form>
dd(request()->all());