Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未定义的属性:laravel中的stdClass::_Laravel - Fatal编程技术网

未定义的属性:laravel中的stdClass::

未定义的属性:laravel中的stdClass::,laravel,Laravel,我想显示用户订单并使用以下代码: @foreach($orderHistory as $order) <div class="with-spacing three-col orders" id="works-grid"> <div class="work-item branding ui-ux"> <div class="work-detail"&

我想显示用户订单并使用以下代码:

@foreach($orderHistory as $order)
                <div class="with-spacing three-col orders" id="works-grid">
                    <div class="work-item branding ui-ux">
                        <div class="work-detail">
                            <a href="#">
                                <img src="images/portfolio-1.jpg" alt="">
                                <div class="work-info">
                                    <div class="centrize">
                                        <div class="v-center">
                                            <h3>{{ $order->product_name }}</h3>
                                            <p> {{ $order->product_price }}</p>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </div>
                    </div>
                </div>
                @endforeach
错误是:“未定义的属性:stdClass::$product\u name”
问题是什么?

问题是,
$order
不是一个对象,您试图像对象一样访问它。也许它是一个数组-尝试这样访问它

我们无法确定,除非我们看到在您的控制器中定义了
$order
。一种快速的方法是在初始化for循环之后放置@dd($order)。这会转储变量,以便查看其格式

您的查询应如下所示:

$orderHistory = DB::table('cart')
            ->where('user_id', auth()->id())
            ->join('singleproducts', 'singleproducts.id', '=', 'cart.product_id')
            ->select('singleproducts.name as product_name', 'cart.qty as quantity', 'cart.product_price as product_price')
            ->get();
        return view('UI.UserProfile.profile' , compact('orderHistory'));
因此,您将得到一个如下格式的对象数组:

[
{
product_name: 'name',
product_price: 555.00,
quantity:  2
}
...
{}
]

问题是,
$order
不是一个对象,您试图像对象一样访问它。也许它是一个数组-尝试这样访问它

我们无法确定,除非我们看到在您的控制器中定义了
$order
。一种快速的方法是在初始化for循环之后放置@dd($order)。这会转储变量,以便查看其格式

您的查询应如下所示:

$orderHistory = DB::table('cart')
            ->where('user_id', auth()->id())
            ->join('singleproducts', 'singleproducts.id', '=', 'cart.product_id')
            ->select('singleproducts.name as product_name', 'cart.qty as quantity', 'cart.product_price as product_price')
            ->get();
        return view('UI.UserProfile.profile' , compact('orderHistory'));
因此,您将得到一个如下格式的对象数组:

[
{
product_name: 'name',
product_price: 555.00,
quantity:  2
}
...
{}
]

输入错误,您正在从数据库中选择“名称”列

@foreach($orderHistory as $order)
    <div class="with-spacing three-col orders" id="works-grid">
        <div class="work-item branding ui-ux">
            <div class="work-detail">
                <a href="#">
                    <img src="images/portfolio-1.jpg" alt="">
                    <div class="work-info">
                        <div class="centrize">
                            <div class="v-center">
                                <h3>{{ $order->name }}</h3>
                                <p> {{ $order->product_price }}</p>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
        </div>
    </div>
@endforeach

输入错误,您正在从数据库中选择“名称”列

@foreach($orderHistory as $order)
    <div class="with-spacing three-col orders" id="works-grid">
        <div class="work-item branding ui-ux">
            <div class="work-detail">
                <a href="#">
                    <img src="images/portfolio-1.jpg" alt="">
                    <div class="work-info">
                        <div class="centrize">
                            <div class="v-center">
                                <h3>{{ $order->name }}</h3>
                                <p> {{ $order->product_price }}</p>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
        </div>
    </div>
@endforeach

显示你的控制器代码!嗯……更新使用
{{$order->name}
,因为字段名是
name
显示控制器代码!嗯……更新使用
{{$order->name}
因为字段名是
name
是的,我认为这是问题所在,我添加了控制器。是的,我认为这是问题所在,我添加了控制器如果解决了问题,接受答案如果解决了问题,接受答案