Php Laravel 4中搜索结果的锚定标记
我创建了一个查询数据库中多个表的搜索。我正在尝试更改每个结果的href,但显然它们有不同的路由/控制器。我在查询中添加了一个自定义属性:Php Laravel 4中搜索结果的锚定标记,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我创建了一个查询数据库中多个表的搜索。我正在尝试更改每个结果的href,但显然它们有不同的路由/控制器。我在查询中添加了一个自定义属性: $enterprise = DB::table('enterprise') ->selectRaw("'enterprise.show' as link") ->where('name', 'LIKE', '%' . $term . '%')
$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
@foreach($r作为结果)
{{Str::limit($r->description,50)}
{{{$r->cost}
@endforeach
但这给了我未定义的属性$r->id。所以,我在我的控制器->select('id',name'等)中添加了另一个select,然后得到未定义的属性$link
我不知道如何将每个结果链接到它们的相关路线/控制器。我怎样才能做到这一点 我很确定这是因为您需要在雄辩的查询的select部分添加其他列 比如:
selectRaw(“id,name,enterprise.show作为链接”)
谢谢,是selectRaw(“enterprise.show”作为链接,id,name,description”)。变量以任何其他方式抛出约束冲突