Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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 5.7中的刀片文件中显示两次_Laravel - Fatal编程技术网

结果将在laravel 5.7中的刀片文件中显示两次

结果将在laravel 5.7中的刀片文件中显示两次,laravel,Laravel,我正在创建要根据通知状态和订单状态显示通知的任务。 从控制器仅获得三条记录,但在刀片文件中循环重复,两条记录两次。 正如预期的输出,我只想显示前三条记录,但它会再次重复第二条和第三条记录。如何消除这种混乱 控制器: public function get_notification() { $userId=Session::get('userid'); $data = DB::select('Select orders.product_id,subcatego

我正在创建要根据通知状态和订单状态显示通知的任务。 从控制器仅获得三条记录,但在刀片文件中循环重复,两条记录两次。 正如预期的输出,我只想显示前三条记录,但它会再次重复第二条和第三条记录。如何消除这种混乱

控制器:

public function get_notification()
    {
        $userId=Session::get('userid');
       $data = DB::select('Select orders.product_id,subcategory.image,GROUP_CONCAT(subcategory.name_of_subcategory) as subcategory,orders.grand_total,orders.deliver_date,orders.order_status,orders.notification_status,orders.orders_id,orders.payment_status,orders.orders_date from orders inner join product_details on FIND_IN_SET(product_details.product_id,orders.product_id) > 0 inner join subcategory on product_details.sub_id=subcategory.sub_id where orders.user_id=? GROUP BY orders.product_id,orders.deliver_date,orders.order_status,orders.orders_id,orders.notification_status,orders.orders_date,orders.payment_status,orders.orders_subtotal,subcategory.image,orders.grand_total',[$userId]);
        return view('notification')->with('data',$data);
    }
刀片:

@foreach($data as $notification)


                    <div class="card-body noti-card" id="noti-card">
                        <div class="row mt-2">


                            <div class="col-sm-2">
                                <div>

                                    <span><img src="{{asset('images/subcategory/'.$notification->image)}}" class="img-fluid" height="100" width="100"></span><br>
                                </div>
                            </div>

                            <div class="col-sm-8">
                                <div>
                                    <span>
                                        <?php
                                            if($notification->notification_status == 1 && $notification->order_status ==1){
                                                echo "<b>Order Placed</b><br>";
                                                echo "Your order for ".$notification->subcategory." with order ID ODI".$notification->orders_id." amounting to Rs.".$notification->grand_total." has been received.";
                                            }
                                            if($notification->notification_status == 2 && $notification->order_status == 2)
                                            {
                                                echo "<b>Order Cancelled</b><br>";
                                                echo "Your order for".$notification->subcategory." with order ID ODI".$notification->orders_id." is successfully cancelled.";
                                            }
                                            if($notification->notification_status == 3 && $notification->order_status == 3)
                                            {
                                                echo "<b>Product Packed</b><br>";
                                                echo "Your package containing ".$notification->subcategory." has been packed by seller and will be shipped soon.";
                                            }
                                            if($notification->notification_status == 4 && $notification->order_status == 4)
                                            {
                                                echo "<b>Product Shipped</b><br>";
                                                echo "Your package containing ".$notification->subcategory." has been shipped by seller and will be delivered soon.";
                                            }
                                            if($notification->notification_status == 5 && $notification->order_status == 5){
                                                echo "<b>Out for Delivery</b><br>";
                                                echo "Your package containing ".$notification->subcategory." from Aarch Ayurved will be delivered today";
                                            }
                                            if($notification->notification_status == 6 && $notification->order_status == 6){
                                                echo "<b>Product Delivered</b><br>";
                                                echo "Your package containing ".$notification->subcategory." has been delivered. Thanks for shopping!";
                                            }

                                        ?>
                                    </span>

                                </div>
                                <div>
                                    <span class="noti-date"><?php
                                    $timestamp = strtotime("$notification->orders_date");
                                    $formattedDate = date('F d, Y', $timestamp);
                                    echo $formattedDate;
                                    ?></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>

    @endsection

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    <script type="text/javascript">
        function loadlink(){
            $('#noti-card').load('/notification #noti-card');
            console.log('TESTING!!!!');
        }
        loadlink();
        setInterval(function(){
            loadlink()
        }, 1000);

    </script>
@foreach($data as$notification)
图像)}}“class=“img fluid”height=“100”width=“100”>
@endforeach @端部 函数loadlink(){ $(“#noti card”).load(“/notification#noti card”); log('TESTING!!!!'); } loadlink(); setInterval(函数(){ loadlink() }, 1000);
输出:


重复最有可能来自查询。您能否在运行查询后立即使用Laravel helper方法
dump()
dd()
对结果进行确认?例如
dd($data)
查询后,您可以立即查看查询返回的结果,并验证它们是否符合预期

我相信问题可能出在产品详细信息的连接上。使用
FIND\u in\u SET()
的目的是什么

如果查询被分成多行,则更容易阅读和理解。如果切换到使用查询生成器,则可能更容易进行故障排除,如下所示:

$data = DB::table('orders')
    ->select([
        'orders.deliver_date',
        'orders.grand_total',
        'orders.notification_status',
        'orders.order_status',
        'orders.orders_date',
        'orders.orders_date',
        'orders.orders_id',
        'orders.payment_status',
        'orders.product_id',
        'subcategory.image',
        DB::raw('GROUP_CONCAT(subcategory.name_of_subcategory) as subcategory'),
    ])
    ->join('product_details', 'orders.product_id', '=', 'product_details.product_id')
    ->join('subcategory', 'product_details.sub_id', '=', 'subcategory.sub_id')
    ->where('orders.user_id', '=', $userId)
    ->groupBy(
        'orders.product_id',
        'orders.deliver_date',
        'orders.order_status',
        'orders.orders_id',
        'orders.notification_status',
        'orders.orders_date',
        'orders.payment_status',
        'orders.orders_subtotal',
        'subcategory.image',
        'orders.grand_total'
    )
    ->get();