Search code examples
laravellaravel-5.6laravel-controller

Return multiple values in laravel


I'm just new in laravel. I want to know. how to return multiple data/value.

public function readItems() {
    $data1 = Data1::all ();
    $data = Data::all ();

    return $data;
}

I'm quite confuse how to do it. I don't to return it as a view, i just want to return only the data. i hope someone could help. thanks a lot..


Solution

  • You could return an array like :

    return [data1, $data];
    

    In the other side read it like :

    $response = readItems();
    
    $data1 = $response[0];
    $data  = $response[1];