Save data in laravel-vue

0

I have a small problem, very basic in my opinion, what happens is that I am trying to save some data, but I can not, this I try to do with vue. in an instance of Vue I have this

newWarranty : {'nombre_garantia' :'', 'valor_garantia' : null, 'descripcion' : ''}

that are the fields that I want to fill, it happens that in my opinion I send them correctly, because it validates me well in laravel, but when I save this record I do not know how to access them. this is my controller and for the moment only valid.

public function store(StoreWarranty $request)
{

return ;
}

and the data sent in this way by axios.

 createWarranty(){
        var url = 'warranties';
        axios.post(url,{
            warranty : this.newWarranty
        }).then(response => {
            vm.getWarranty();
            vm.newWarranty = {'nombre_garantia' :'', 'valor_garantia' : null , 'descripcion' : ''};
            vm.errors = [];
            $('#create').modal('hide');
            $.notify('Nueva tarea creada con exito','success');
        }).catch(error => {
            vm.errors = error.response.data.errors
        })
    }
    
asked by Alexi Gallegos Perez 03.05.2018 в 04:31
source

1 answer

0

Hello, I recommend that in the return you send in response:

return response()->json([$reuqest->all()]);

and you look at the network that the controller is sending you in response to.

On the one hand if you have error in the request there you will see clearly what the error is and on the other hand you will see with what structure your data arrives.

In your case you can access your data with the following line of code.

$data = $request->input('newWarranty ');

$ data becomes the object that you have on the clients side so to enter each element of the object you must do it from the following font.

$data->newWarranty ->nombre_garantia  // te regresa nombre_garantia

$data->newWarranty ->valor_garantia// te regresa valor_garantia aun que sea nu

$data->newWarranty ->descripcion// te regresa descripcion

If I get it wrong if I do what I tell you, you can see clearly if it is an object or an arrangement.

to access the properties of the objects you use "->"

and to enter the properties of an array you use "[]"

    
answered by 31.08.2018 в 05:02