The controller code is given below:
class GetProductController extends Controller
{
public function show(){
$products = Whmcs::GetProducts([
'pid'=>'pid',
'name' =>'name',
'price' =>'price',
'description' =>'description'
]);
return view('main.SME_Hosting',['products'=>$products]);
}
}
The code using foreach is as follows:
@foreach ($products as $product)
{{$product}}
@endforeach
I'm getting an error as Expecting string not an array given.. and Undefined variable 'pid'.
The Route code is:
Route::get('SME_Hosting','GetProductController@show');
Suggest a solution to decode the json data and display it.
Try this: class GetProductController extends Controller { public function show(){
$products = Whmcs::GetProducts([
'pid',
'name',
'price',
'description'
]);
return view('main.SME_Hosting',['products'=>$products]);
}
And in view:
@foreach ($products as $product)
{{$product->name}}
@endforeach