Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

View

@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

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'));

Model

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');
}
    }

Controller

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

enter image description here

how can I fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
844 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...