lundi 10 août 2020

Laravel: How to save an array of objects sent from the frontend?

I have an endpoint I am calling to save an array of objects:

Frontend

saveLinks: function() {
    let links = [{"title": "Welcome", "url": "http://www.ccc.com"}, {"title": "Bye", "url": "http://www.ddd.com"}];
    
    axios.post('/admin/endpoint', {
        link_data: links
    }

}

Laravel

public function saveLinks(Request $request) 
{
    $links = $request->link_data;

    $user = User::where('id', '=', 1)->first();
    
    $user->links = $links;
    $user->save();
 
}

my links field is empty though. Am I sending the data over incorrectly for an array an objects?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire