获取未定义的索引:Yajra 数据表中的状态 Laravel 6.xx

Getting undefined index: status in Yajra Datatable with Laravel 6.xx

第一个table"Offers"我店里有优惠详情。如果报价状态 = public 那么每个人都可以访问并且状态将显示在 Yajra 数据 table 中 "Approved"。

否则,如果 offer status = request,用户可以请求访问。当他们提交访问请求时,它将与用户 ID 和报价 ID 一起存储在报价请求 table 中,状态 = 0 表示在 yajra 数据 table 状态待处理。然后管理员可以在 yajra datatable status approve.

中设置 status = 1 mean

我在这段代码中遇到了这个错误。

注意:抱歉英语不好

->editColumn('status', function(Offer $offer) {

                if($offer->offer_permission == 'public')
                {
                    $status = '<span class="badge badge-primary">Approve</span>';

                }elseif($offer->offer_permission == 'request')
                {
                    $checkstatus= OfferRequest::select('status')->where('offer_id', $offer->id )->where('user_id', Auth::id())->pluck('status')->toArray();

                      if($checkstatus['status'] == 0)
                         {
                                $status = '<span class="badge badge-secondary">Pending</span>';

                         }elseif ($checkstatus['status'] == '1')
                         {
                                $status = '<span class="badge badge-primary">Approve</span>';

                         }elseif ($checkstatus['status'] == '2')
                         {
                                $status = '<span class="badge badge-danger">Rejected</span>';

                         }elseif ($checkstatus['status'] == '3')
                         {
                                $status = '<span class="badge badge-danger">Blocked</span>';

                         }else
                         {
                             $status = '<a href="' . route('offers.show', $offer->id) .'"><span class="badge badge-secondary">Apply Now</span></a>';
                         }

                }

                return $status;

            })

我认为你应该为 checkstatus 变量添加检查点,无论它是否为空。

editColumn('status', function(Offer $offer) {

            if($offer->offer_permission == 'public')
            {
                $status = '<span class="badge badge-primary">Approve</span>';

            }elseif($offer->offer_permission == 'request')
            {
                $checkstatus= OfferRequest::select('status')->where('offer_id', $offer->id )->where('user_id', Auth::id())->pluck('status')->toArray();
                if(empty($checkstatus)){
                  if($checkstatus['status'] == 0)
                     {
                            $status = '<span class="badge badge-secondary">Pending</span>';

                     }elseif ($checkstatus['status'] == '1')
                     {
                            $status = '<span class="badge badge-primary">Approve</span>';

                     }elseif ($checkstatus['status'] == '2')
                     {
                            $status = '<span class="badge badge-danger">Rejected</span>';

                     }elseif ($checkstatus['status'] == '3')
                     {
                            $status = '<span class="badge badge-danger">Blocked</span>';

                     }else
                     {
                         $status = '<a href="' . route('offers.show', $offer->id) .'"><span class="badge badge-secondary">Apply Now</span></a>';
                     }
                }else{
                    $status = '<a href="' . route('offers.show', $offer->id) .'"><span class="badge badge-secondary">Apply Now</span></a>';
                }

            }

            return $status;

        })

试试吧!