1

我想从数组值创建链接的目的是链接将显示详细信息的模式。

所以我有这个数组:

array:1 [▼
  42 => "00285",
  43 =? "00123"
]

我找到了一些这样的方法:

foreach ($certificate->pluck('number', 'id')->toArray() as $href => $text) {
    if ($href != $text) {
        echo '<a href="?page=' . $href . '">' . $text . '</a>, ';
    } else {
        echo $text;
    }
}

但在某些情况下,我的控制器将中断到下一个网格“回声”必须是“返回”,

我想要的示例网格:

在此处输入图像描述

但是上面的代码会显示如下:

在此处输入图像描述

在第一张图片中未显示网格内的值

编辑:

我的图片 1 中的代码 - [laravel-admin]:

$grid->column('Sertifikat')->display(function () {
    $skips = ["[", "]", "\""];
    $certificate = LandCertificate::where('data_order_id', $this->id);
    $costumerName = Costumer::where('id', $this->costumer_id);

    $certificateNumberArray = $certificate->pluck('number') ?? null;
    $temp1 = str_replace($skips, '', $certificateNumberArray);
    $certificateNumber = str_replace(',', ', ', $temp1);

    if ($certificate->pluck('owner') != $costumerName->pluck('name')) {
        return "<span class='text-danger'>$certificateNumber</span>";
    } else
        return $certificateNumber;
});

实际上,该代码仅在图片 1 处显示结果,而没有像图片 2 那样的链接

刀片代码:

https://github.com/z-song/laravel-admin/blob/master/resources/views/grid/table.blade.php

4

2 回答 2

0

您必须使用 html_entity_decode

if ($certificate->pluck('owner') != $costumerName->pluck('name')) {
     return html_entity_decode("<span class='text-danger'>$certificateNumber</span>");
} else {
    return $certificateNumber;
}
于 2019-11-27T02:08:47.977 回答
0

我找到了解决此问题的解决方案。

尝试获取数组值,然后通过如下修改将其返回:

我的控制器:

$grid->column('Sertifikat')->display(function () {
    $skips = ["[", "]", "\""];
    $certificate = LandCertificate::where('data_order_id', $this->id);
    $costumerName = Costumer::where('id', $this->costumer_id);

    foreach ($certificate->pluck('number', 'id')->toArray() as $href => $text) {
        if ($href != $text) {
            if ($certificate->pluck('owner') != $costumerName->pluck('name')) {
                $certificateDetail[] = "<a href='#' data-toggle='modal' data-target='#messageModal' data-id='{$href}' data-from='{$href}' data-title='{$href}' data-message='{$href}' data-time='{$href}'><span class='text-danger'>$text";
            } else
                $certificateDetail[] = "<a href='#' data-toggle='modal' data-target='#messageModal' data-id='{$href}' data-from='{$href}' data-title='{$href}' data-message='{$href}' data-time='{$href}'>$text";
        } else {
            $certificateDetail[] = $text;
        }
    }

    $certificateNumberArray = $certificate->pluck('number') ?? null;
    $temp1 = str_replace($skips, '', collect($certificateDetail));
    $certificateNumber = str_replace(',', ', ', $temp1);

    return $certificateNumber;
});

结果:

证书列可链接

于 2019-11-28T03:13:12.313 回答