1 year ago

Laravel + VUE Form Request

Posted 1 year ago by murilo

Hello Guys , I am sending data from VUE to Laravel with AXIOS , I am using json_decode() in Laravel to decode the data , I am making the samething in FormRequest , But I am having problem to make the json_decode() in forms with arrays .

I GET All those data I get like this in Laravel ->

$title = json_decode($request['title']);
Instead of 

$title = $request['title'];

Well , It is working fine . But the problem is the form request , it is like this -

return [
            'title' =>  'required',

    // I can not make , json_decode() inside here .

So I found a class on Internet , that Extend Form Request to send those data from VUE Js .

It is like this -

abstract class Request extends FormRequest
    protected function validationData()
        $data = $this->all();

        // if is not an array , so json_decode()
        foreach ($data as $key => $form_items) {

            if(! is_array($form_items)){
        // here is not array , is making json_decode() in filds that is not array , it is working   
                $data[$key] = json_decode($form_items);

                // HERE IS ARRAY , I DIDNT MANAGED 
        // I dont know how I could use json_decode() here inside , I used foreach() .... and every thing , but It didnt work , I should make some change here to be able to use json_decode() in arrays .

                $data[$key] = $form_items;


        return $data;


It is very hard to explain , I dont know if some one will understand , but thanks if some one help me .

Please sign in or create an account to participate in this conversation.