How can I convert json to a Laravel Eloquent Model?

后端 未结 5 1533
無奈伤痛
無奈伤痛 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:27

    Can you try it like this?

    public function store($poststuff)
    {
        $post = new Post;
        $post->text = $poststuff['text'];
        $post->save();
    }
    

提交回复
热议问题