简体   繁体   English

此集合实例上不存在属性 [order_number]。 拉拉维尔 9.x

[英]Property [order_number] does not exist on this collection instance. laravel 9.x

I am trying to print out queried results from my db to a view after successfully making payments.成功付款后,我正在尝试将查询的结果从我的数据库打印到视图中。 However, when i try to access the data passed to the view, i get the error below但是,当我尝试访问传递给视图的数据时,出现以下错误

Property [order_number] does not exist on this collection instance.

I already did var_dump on the collection, and it returns the properties and values, but when i try to access it like so $orderDetails->column_name i get an error我已经在集合上做了var_dump ,它返回了属性和值,但是当我尝试像这样访问它时$orderDetails->column_name我得到一个错误

below is my method下面是我的方法

  public function complete(Request $request)
{

    $paymentId = $request->input('paymentId');
    $payerId = $request->input('PayerID');

    $status = $this->payPal->completePayment($paymentId, $payerId, $request->order_number);

    $order_number = $request->order_number;

    $order = Order::where('order_number', $order_number)->first();
    $order->status = 'processing';
    $order->payment_status = 1;
    $order->payment_method = 'PayPal';
    $order->save();

    Cart::clear();

    $orderDetails = Order::where('order_number', $order_number)->get();

    return view('frontend.pages.order-success', [
        'orderDetails' => $orderDetails
    ]);

    // return redirect()->route('/')->with('message', 'Your Order has been placed successfully! We will contact you with the details you provided');
}

and here is my view page这是我的视图页面

    @extends('frontend.layouts.main')

    @section('title', 'Order Successful')

 @section('content')
 <!-- Main Content -->
 <div id="main-content" class="site-main clearfix">

     <section class="order-detail themesflat-section">
         <div class="themesflat-container">
             <div class="top-order text-center">
                 <h5 class="heading">Congratulation! You’ve completed payment.</h5>
                 <div class="order-infor">
                     <div class="item number">
                         <div class="title">Order Number</div>
                         <div class="content">
                             {{ $orderDetails->order_number }}
                         </div>
                     </div>
                     <div class="item date">
                         <div class="title">Date</div>
                         <div class="content">12 August 2020</div>
                     </div>
                     <div class="item total">
                         <div class="title">Total</div>
                         <div class="content"></div>
                     </div>
                     <div class="item payment">
                         <div class="title">Payment Method</div>
                         <div class="content">Check Payments</div>
                     </div>
                 </div>
             </div>
             <div class="main-order">
                 <div class="heading">Order Details</div>
                 <table class="table-order">
                     <tbody>
                         <tr class="title">
                             <th class="product-infor">Product</th>
                             <th class="price">Price</th>
                         </tr>


                         <tr class="item">
                             <td>
                                 <div class="title-product"><a href="#"></a></div>
                             </td>
                             <td class="price">
                                 <div class="price-inner"></div>
                             </td>
                         </tr>


                     </tbody>
                 </table>
             </div>
         </div>
     </section>

 </div><!-- /#main-content -->
 @endsection

you are trying to get properties from a collection, not from a single item then it won't work.您正在尝试从集合中获取属性,而不是从单个项目中获取属性,那么它将不起作用。

change:改变:

$orderDetails = Order::where('order_number', $order_number)->get();

by:经过:

$orderDetails = Order::where('order_number', $order_number)->firstOrFail();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 此集合实例上不存在属性 [图像]。 / Laravel - with() 方法 - Property [image] does not exist on this collection instance. / Laravel - with() Method 该集合实例上不存在属性[associated_occupation]。 -Laravel - Property [associated_occupation] does not exist on this collection instance. - Laravel 此集合实例上不存在属性 [vegan]。 Laravel - Property [vegan] does not exist on this collection instance. Laravel 该集合实例上不存在属性[title]。 拉拉韦尔5.5 - Property [title] does not exist on this collection instance. laravel 5.5 (1/1)异常属性[price]在该集合实例上不存在。 (Laravel 5.4) - (1/1) Exception Property [price] does not exist on this collection instance. (Laravel 5.4) 此集合实例上不存在属性 [expiry_date]。 在 Laravel - Property [expiry_date] does not exist on this collection instance. in Laravel “此集合实例上不存在属性 [角色]。” - "Property [role] does not exist on this collection instance." Laravel错误:此集合实例上不存在属性[id]。 但是它可以在本地服务器上运行 - Laravel Error: Property [id] does not exist on this collection instance. Yet it works on the local server “此集合实例上不存在属性[registration_types]。” - “Property [registration_types] does not exist on this collection instance.” 该集合实例laravel关系上不存在属性[X] - Property [X] does not exist on this collection instance laravel relationship
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM