Kirolos Victor
Kirolos Victor

Reputation: 43

ErrorException: Undefined index: id

I'm trying to fetch data from this JSON URL https://api.github.com/users/Kirolos-victor/events/public but I don't understand why am I getting this error I hope someone can help me, Thanks.

 public function score(Request $request)
{
    $validator=Validator()->make($request->all(),[
        'name'=>'required',

    ]);
    if($validator->fails())
    {
        return response()->json(['message'=>'failed','data'=>$validator->errors()],400);

    }
    $json=Http::get("https://api.github.com/users/$request->name/events/public")->json();
    $id=collect($json["id"]);
    return $id;
}

Upvotes: 0

Views: 734

Answers (1)

Kyle
Kyle

Reputation: 1503

looks like that end point is an array of json so collect($json[0]["id"]);

Upvotes: 2

Related Questions