0

I've just started laravel and when I try to get values from database it's fine. But when I try to return the values, it's just empty. Here's the code:

 public function index()
{
    $collection = [];
    Leg::chunk(200, function ($data) {

        foreach ($data as $val) {
            $collection[] = [
                'fixture_id' => $val->fixture_id,
                'ops_leg_id' => $val->ops_leg_id,
                'designator' => $val->designator,
                'operator' => $val->operator,
                'flight_number' => $val->flight_number,
                'dep_airport' => $val->dep_airport,
                'arr_airport' => $val->arr_airport,
                'ac_registration' => $val->ac_registration,
                'ac_code' => $val->ac_code,
                'sta_at' => $val->sta_at,
                'std_at' => $val->std_at,
                'ata_at' => $val->ata_at,
                'atd_at' => $val->atd_at,
                'deleted' => $val->deleted
            ];


        }
    });
    return array($collection);

}

Edit: My output of the webpage is just [[]]

1 Answer 1

1

The inline function does not return anything

public function index()
{

    Leg::chunk(200, function ($data) {

        $collection = [];
        foreach ($data as $val) {
            $collection[] = [
                'fixture_id' => $val->fixture_id,
                'ops_leg_id' => $val->ops_leg_id,
                'designator' => $val->designator,
                'operator' => $val->operator,
                'flight_number' => $val->flight_number,
                'dep_airport' => $val->dep_airport,
                'arr_airport' => $val->arr_airport,
                'ac_registration' => $val->ac_registration,
                'ac_code' => $val->ac_code,
                'sta_at' => $val->sta_at,
                'std_at' => $val->std_at,
                'ata_at' => $val->ata_at,
                'atd_at' => $val->atd_at,
                'deleted' => $val->deleted
            ];
        }
        return array($collection);
    });

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.