laravel unserialize jquery form data

laravel unserialize form data

In this article, we learn how we can unserialize jquery form data in laravel, I will show you the step-by-step process so that you can understand how we can unserialize jquery data in laravel.

You can also learn how we can send csrf token with the ajax form submission.

Below is the ajax code in which I am taking the form data, using the form.serialize jquery method.

var data = $('#form').serialize();
                var url = '{{ route("store.terms") }}';
                axios({
                    method: 'POST',
                    url: url,
                    data: {
                    "_token": "{{ csrf_token() }}",
                    "data": data
                    }
                })

Below is my business logic is written in the controller when I am receiving the serialize data, sent by the jquery for, you can unserialize the data by using parse_str method.

/**
     * Store and update the terms
     * @return response 
     * @param  Request $request
     */
    public function storeUpdateTerms(Request $request)
    {   
        $unserializeData = [];
        parse_str($request->data,$unserializeData);
        dd($unserializeData);
    }

You can get a response like the below one.


0 0 votes
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x