gpt4 book ai didi

php - Laravel 4 中搜索结果的 anchor 标签

转载 作者:行者123 更新时间:2023-11-28 23:38:50 26 4
gpt4 key购买 nike

我创建了一个查询数据库中多个表的搜索。我正在尝试更改每个结果的 href,但显然它们有不同的路由/ Controller 。我在查询中添加了一个自定义属性:

$enterprise = DB::table('enterprise')
->selectRaw("'enterprise.show' as link")
->where('name', 'LIKE', '%' . $term . '%')
->orWhere('description', 'LIKE', '%' . $term . '%');
$entertainment = DB::table('entertainment')
->selectRaw("'entertainment.show' as link")
->where('name', 'LIKE', '%' . $term . '%')
->orWhere('description', 'LIKE', '%' . $term . '%');

当我将查询与其余查询合并时,这会起作用。然后在我看来有一个 foreach 循环:

@foreach($results as $r)
<div class="col-lg-3" style="padding-top: 20px">
<div class="hpanel">
<div class="panel-body text-center h-200">
<a style="color: #3c763d" href="{{route($r->link, $r->id)}}">
<h4 class="font-extra-bold no-margins text-success">{{Str::limit($r->name, 15)}}</h4></a>
<small>{{ Str::limit($r->description, 50) }}</small>
</div>
<div class="panel-footer">
<i class="fa fa-gbp"><p style="display: inline"> {{$r->cost}}</p></i>
</div>
</div>
</div>
@endforeach

但这给了我未定义的属性 $r->id。因此,我将另一个选择添加到我的 Controller ->select('id', 'name' et al) 然后我得到未定义的属性 $link。

我不知道如何将每个结果链接到它们的相关路由/ Controller 。我怎样才能做到这一点?

最佳答案

我很确定这是因为您需要在 Eloquent 查询的选择部分添加其他列。

类似于:

selectRaw("id, name, enterprise.show as link")

关于php - Laravel 4 中搜索结果的 anchor 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34934995/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com