在数据对象laravel api中添加更多值

时间:2018-05-24 06:25:40

标签: php laravel

$st = 'Something';
return Response::json([
            "success" => true,
            "message" => "User found",
            "st" => $st,
            "data"    => Auth::user()->load(['ch' => function ($query) {
                            $query->noGu()
                                        ->with('sp');
                    },
                    'sp' => function($query){
                        return Auth::user()->sp;
                    }])
        ], 200);

我怎样才能进入"数据"我试过的对象' st' => $ st,对我来说不起作用请建议提前感谢

1 个答案:

答案 0 :(得分:1)

        $st = 'Something';
    return Response::json([
                "success" => true,
                "message" => "User found",
                "st" => $st,
                 //Take the use statement
                "data"    => Auth::user()->load(['ch' => function ($query) use ($st) {
                                //Now you can use $st inside this function
                                $query->noGu()->with('sp');
                        },
                        'sp' => function($query){
                            return Auth::user()->sp;
                        }])
            ], 200);