0

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 !!}

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.