不允许序列化“闭包" - laravel

Serialization of #39;Closure#39; is not allowed - laravel(不允许序列化“闭包 - laravel)
本文介绍了不允许序列化“闭包" - laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的表中创建一个元组.数据来自表格或收到.我的数据库:

I'm trying to create a tuple in my table. The data is from a form or received. My database:

查看

@extends('plantilla')
@section('contenido')
<div class="formulario">
{{Form::open(array('url' => 'servicio/create', 'files' => true))}}

    <input type="text" class="form-control"  id="direccion" name="dirrecion" placeholder="Dirección" >
    <input type="text" class="form-control"  id="cliente" name="cliente" placeholder="Nombre Cliente" >
    <input type="time" name='horainicio' id='horainicio' min='time' max='time' >
    {{Form::file('pdf', array('title' => 'Search for a file to add'))}}
    {{Form::select('idtecnico', $tecnico_selector)}}
    {{ Form::submit('Guardar', array('class' => 'btn btn-primary ')) }} 
{{Form::close()}}
    </div>  
    @stop

路线

Route::get('servicio/create', function(){
$tecnicos = Tecnico::all();
    $tecnico_selector = array();
    foreach ($tecnicos as $tecnico) {
        $tecnico_selector[$tecnico->idTecnico] = $tecnico->Nombre;
    }
    return View::make('formservicio', array('tecnico_selector' => $tecnico_selector));
 });
 Route::post('servicio/create', array('uses' => 'ServicioController@doCreate'));

型号

class Servicio extends Eloquent{
protected $table = 'Servicio';
protected $primaryKey = 'idServicio';
protected $fillable = array(
                            'Direccion',
                            'RutaPDF',
                            'Completado'
                            );
public function materialUsado(){
    return $this->hasMany('Material_Usado', 'idMaterial_Usado');
}

public function tecnicos(){
    return $this->belongsToMany('Tecnico', 'Servicio_Tecnico', 'Servicio_idServicio', 'Tecnico_idTecnico');
}
    }

控制器

class ServicioController extends BaseController{
public function doCreate(){
    $rules = array(
                'idtecnico' => 'required',
                'direccion' => 'required',
                'cliente' => 'required'
                );
    $validator = Validator:: make(Input::all(), $rules);

    if($validator->fails()){
        return Redirect::to('servicio/create')
                ->withErros($validator)
                ->withInput();
    }else{
        $input = array(
                'Direccion' => Input::get('direccion'),
                'Cliente' => Input::get('cliente'),
                'Completado' => '0'
                );

        Servicio::create($input);
        /*$servicio = new Servicio;
        $servicio->Direccion = Input::get('direccion');
        $servicio->Cliente = Input::get('cliente');
        $servicio->Completado = '0';
        $servicio->tecnicos->attach($idtecnico);
        $servicio->save();*/

        $path = public_path().'/servicio/'.$servicio->idServicio;
        File::makeDirectory($path, $mode = 0777, true, true); // creamos la carpeta
        $archivoPdf = Input::file('pdf');
        $archivoPdf->move($path, 'servicio');

        /*$servicio->RutaPDF = $path.'/servicio';
        $servicio->save();*/







    }
}
}

当完全改变表单并发送时,出现以下错误

When completely changes the form and send it, the following error

我该如何解决?

推荐答案

你的控制器有错字:->withErros($validator) - 它应该是 withErrors.差别很大.

You have a typo in your controller: ->withErros($validator) - it should be withErrors. The difference is big.

Laravel 将 withErros($validator) 转换为 with(['erros' => $validator]),意思是尝试将整个验证器对象放入会议.要将东西放入会话存储中,首先需要对其进行序列化,这就是导致错误的原因.

Laravel converts withErros($validator) into with(['erros' => $validator]), which means trying to put the entire validator object into the session. To put things into the session storage, it needs to be serialized first, which is what is causing the error.

这篇关于不允许序列化“闭包" - laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)