Returning an Eloquent model as JSON in Laravel 4

前端 未结 4 809
既然无缘
既然无缘 2021-01-01 09:13

How do you return an Eloquent model to the browser as JSON? What is the difference between the two methods below? Both seems to work.

#1:

         


        
4条回答
  •  梦谈多话
    2021-01-01 09:19

    this solved my problem in laravel 5.5:

    function allUsers()
    {
        $users = \App\User::all();
        $usersJson = json_encode($users);
        return $usersJson;
    }
    

提交回复
热议问题