db_val
这是我的代码:
@foreach($details as $value)
<a href="{{route(' **Here** ')}}"> {{$value['category']}}</a>
@endforeach
控制器功能:
public function viewhome(Request $req){ $product = product::all()->unique('category'); return view('homepage',['details'=> $product]);}
路线:
Route::get('/homepage/db_val', 'HomeController@db_val')->name('db_val');
如何正确声明我想在{{route('')}}中设置{{$ value ['category']}}}这是我的代码:@foreach($ details as $ value) {{$value['category']}} @endforeach ...] >href
。路线将是什么。谢谢。
db_val
Route :: get('/ homepage / db_val','HomeController @
showcategorie')-> name('showcat');
2)route
与命名路由一起使用您有一个名为'db_val'的路由-> Route :: ....-> name(db_val);所以必须这样使用,<a href='{{route('db_val')}}
3)在您的情况下,假设foreach中的$ value是一个内部带有“类别”索引的数组您可以使用url代替route
@foreach($details as $value)
<a href="{{url('/your_url')}}/{{$value['category']}}">
link to {{$value['category']}}
</a>
@endforeach
4)但剑灵是
Route::get('/showcategory/{id}','HomeController@showcategorie')->name('showcat');
视图
@foreach($details as $value) <a href="{{route('showcat', $value['category'])}}"> @endforeach
db_val