Reputation: 79
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
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
Reputation: 11
You can send data to view as like below :
return view('index', ['Data_One'=>$data, 'Data_Two'=>$data1]);
Upvotes: 1
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