试图在demo.blade.php中获取非对象的属性'id'

问题描述 投票:0回答:1

[您好,我正在laravel的结帐页面上工作,并将购物车中的一些产品数据发送到结帐,并尝试从json对象打印所有详细信息,但由于尝试获取非-的属性“ id”,我一直收到错误消息对象

控制器功能是

public function bill(Request $request){

            $input = $request->all();

            return view('demo')->with('product' , $request->product)
                              ->with('subtotal' , round($request->subtotal));
        } 

购物车表格是

<form method="post" action="{{ route('pay')}}">
                                {{ csrf_field() }}

                                @foreach($cart as $product)
                                 <input type="hidden" name="product[]" value="{{ $product }}">
                                @endforeach

                                <input type="hidden" name="subtotal" value="{{$subtotal}}">
                                <button type="submit" class="gray_btn">Checkout</button>
                              </form></a>

刀片页面是

@foreach($product as $input)

{{ $input }}

{{ $input->id }}

@endforeach

[当我仅打印输入内容时,我得到的结果为

{"id":"10","name":"S007-4ft","price":40,"quantity":"102","attributes":{"image":"glassfilms\/December2019\/MyelERNBbAWhGRbKWiCK.jpg","crm":"PRO209"},"conditions":[]} {"id":"7","name":"Frosted 007-4ft","price":40,"quantity":"103","attributes":{"image":"glassfilms\/December2019\/ZJgWUNaYrPnvsoRfuagv.jpg","crm":"PRO105"},"conditions":[]} 

但是当我尝试仅使用{{input->id }}打印ID时,出现错误。

路线是

Route::post('pay', 'RazorpayController@bill')->name('pay');
php arrays json laravel laravel-5
1个回答
0
投票
您正在将json object用作php object,请先解码json对象,然后再将其用作php对象:

$obj = json_decode($input); $obj->id // Now you can use it like this

© www.soinside.com 2019 - 2024. All rights reserved.