繁体   English   中英

搜索结果的锚点标签在Laravel 4中

[英]Anchor tags for search results in Laravel 4

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

$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。 因此,我在控制器中添加了另一个选择-> select('id','name'等),然后得到未定义的属性$ link。

我不知道如何将每个结果链接到其相关的路由/控制器。 我该如何实现?

我很确定这是因为您需要在雄辩的查询的select部分中添加其他列。

就像是:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM