How can I convert json to a Laravel Eloquent Model?

后端 未结 5 1544
無奈伤痛
無奈伤痛 2021-02-20 02:43

if I have an Eloquent Model called Post, and the mysql table has:

integer ID, string Text

How do I convert this JSon:

{ post: { text: \'my text\'         


        
5条回答
  •  半阙折子戏
    2021-02-20 03:13

    Just turn it to array and fill an eloquent

    $arr = json_decode($json, true);
    $post = new Post;
    $post->fill($arr);
    

提交回复
热议问题