chimichi004
chimichi004

Reputation: 79

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..

Upvotes: 4

Views: 7327

Answers (3)

Madusha Prasad
Madusha Prasad

Reputation: 57

you can return value like this

[
            'couponName' => $coupon->couponName,
            'couponCode' => $coupon->couponCode,
            'qty' => $coupon->qty,
            'startDate' => $coupon->startDate,
            'endDate' => $coupon->entDate,
            'userId' => $coupon->userId,
]

Upvotes: 0

The Coder
The Coder

Reputation: 11

You can send data to view as like below :

return view('index', ['Data_One'=>$data, 'Data_Two'=>$data1]); 

Upvotes: 1

Zakaria Acharki
Zakaria Acharki

Reputation: 67505

You could return an array like :

return [data1, $data];

In the other side read it like :

$response = readItems();

$data1 = $response[0];
$data  = $response[1];

Upvotes: 6

Related Questions