Reputation: 3
Controller:
$commission = Commission::findOrFail($id);
$json_calculation = (array) json_decode($commission->price_calculation, true);
return view('tradesman.commissions-list-detail')
->with('commission', $commission)
->with('calculations', $json_calculation);
JSON:
{"price_per_hour":"180","hours":"4","material_type_1":"Something","material_price_1":"1200","material_type_2":"Something","material_price_2":"800"}
View:
@forelse($calculations as $calculation)
<p>{!! $calculation->price_per_hour !!}</p>
Error:
ErrorException: Trying to get property of non-object
If i use just {!! $calculation !!} it works but i need something like {!! $calculation->material_type1 !!}
Upvotes: 0
Views: 144
Reputation: 5135
You are converting your Json into Array, that's you would not able to access your key like object. So change your this line
$json_calculation = (array) json_decode($commission->price_calculation, true);
like this and then try. it will decode your json like object
$json_calculation = json_decode($commission->price_calculation);
Upvotes: 1