проблема с загрузкой файлов в laravel
Я пытаюсь загрузить файл с laravel, но при отправке формы он дает следующую ошибку
исключение
сериализация "SymfonyComponentHttpFoundationFileUploadedFile" не допускается
вот мой клинок:
{{ Form::open(array('route' => 'drivers.store', 'files' => true, 'class' => 'form-horizontal')) }}
<form role="form">
<div class="form-group first-field">
{{ Form::label('first_name', 'First Name:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4 ">
{{ Form::text('first_name', $value = null, array('placeholder' => 'ex-Jon', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('first_name') }} </span>
<div class="form-group">
{{ Form::label('last_name', 'Last Name:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('last_name', $value = null, array('placeholder' => 'ex-Doe', 'required' => 'required', 'class' => 'form-control', 'class' => 'form-control')) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('last_name') }} </span>
<div class="form-group">
{{ Form::label('email', 'Email:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('email', $value = null, array('placeholder' => 'ex-test@example.com', 'rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('email') }} </span>
<div class="form-group">
{{ Form::label('contact_number', 'Phone:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('contact_number', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('contact_number') }} </span>
<div class="form-group">
{{ Form::label('sin', 'SIN:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('sin', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('sin') }} </span>
<div class="form-group">
{{ Form::label('license_number', 'License Number:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('license_number', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('license_number') }} </span>
<div class="form-group">
{{ Form::label('license_file', 'License File:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::file('license_file') }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('license_file') }} </span>
<div class="form-group">
{{ Form::label('street_address', 'Street Address:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('street_address', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('street_address') }} </span>
<div class="form-group">
{{ Form::label('password', 'Password:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::password('password',array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-text">Between 6 and 12 Characters</span>
</div>
<span class='error-text'> {{ $errors->first('password') }} </span>
<div class="form-group">
{{ Form::label('password_confirmation', 'Confirm Password:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::password('password_confirmation', array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
</div>
<div class="form-group">
{{ Form::submit('Add Driver', array('class' => 'btn btn-primary center-block sh-request-button sign-up')) }}
</div>
</form>
{{ Form::close() }}
контроллер//:
public function store()
{
$input = Input::all();
////echo "</pre>";print_r($input); $file= Input::file('license_file.name');
$validator = $this->_modelDriver->validator($input);
if ($validator->fails()) {
return Redirect::route('drivers.create')->withInput($input)->withErrors($validator);
}
else {
echo "test success";exit;
}
}
//проверяющего:
public function validator(array $input, $isUpdate=false)
{
if(!$isUpdate) {
$rules = array(
'first_name'=>'required|alpha|min:2',
'last_name'=>'required|alpha|min:2',
'email'=>'required|email|unique:drivers',
'password'=>'required|between:6,12|confirmed',
'password_confirmation'=>'required|between:6,12'
);
} else {
$rules = array(
'firstname'=>'required|alpha|min:2',
'lastname'=>'required|alpha|min:2',
'email'=>'required|email',
);
}
return Validator::make($input, $rules);
}
Я новичок в laravel. Так что если кто-то может сказать, что я делаю неправильно и как это исправить.
спасибо
1 ответов
это происходит потому, что вы пытаетесь вернуться с входного файла.
вы должны написать это
$input = \Input::except('license_file');
return \Redirect::route('drivers.create')->withInput($input)->withErrors($validator);
вместо
return \Redirect::route('drivers.create')->withInput($input)->withErrors($validator);