想在Laravel的{{$value['category']}}中添加{{$ value ['category']}}},

问题描述 投票:0回答:1
我想在{{route('')}}}中设置{{$ value ['category']}}}>

这是我的代码:

@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');

如何正确声明

href

。路线将是什么。谢谢。
我想在{{route('')}}中设置{{$ value ['category']}}}这是我的代码:@foreach($ details as $ value) {{$value['category']}} @endforeach ...] >

1)警告:您在HomeController中调用db_val函数,但在问题中显示了viewhome方法。路线:: get('/ homepage / db_val','HomeController @

db_val

')-> name('db_val'); 如果您想使用viewhome方法:

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.php

Route::get('/showcategory/{id}','HomeController@showcategorie')->name('showcat');

视图

@foreach($details as $value) <a href="{{route('showcat', $value['category'])}}"> @endforeach

php laravel laravel-5 laravel-4
1个回答
0
投票
1)警告:您在HomeController中调用db_val函数,但在问题中显示了viewhome方法。路线:: get('/ homepage / db_val','HomeController @

db_val

© www.soinside.com 2019 - 2024. All rights reserved.