如何在 laravel 的下一个视图中打印通过 get 方法传递的值?
How to print values passed by get method in next view in laravel?
我已经通过
为我的 get 路由传递了参数
<a href="{{ route('product.list', $product->category) }}" class="btn btn-primary btn-lg">Show more</a>
我的路线是
Route::get('list/{category}', ['as' => 'tour.featured', 'uses' => 'PublicController@productList']);
我想在我的产品-list.blade.php视图中显示类别名称
这是我试过的:
{{$_GET['category']}}
这给我错误
Undefined index: category
使用{{request()->route('category')}}
您还差一步:
Route::get('list/{category}', ['as' => 'tour.featured', 'uses' => 'PublicController@productList']);
之后,您必须在 PublicController 中创建 productList 方法,例如
function PublicController(Request $request)
{
echo $request; // will print the data in $product->category
// Now you can pass this value to your view like:
return view('view_name', array('category', $product->category));
}
并像这样查看:
{{$_GET['category']}}
使用相同的路线并使您的控制器像:
public function yourMethod($category)
{
// other stuff here, will return value for $category
return view('someview', COMPACT('category'));
}
现在您可以在 blade 文件中使用 $category 值,例如:
{{ $category }}
我已经通过
为我的 get 路由传递了参数 <a href="{{ route('product.list', $product->category) }}" class="btn btn-primary btn-lg">Show more</a>
我的路线是
Route::get('list/{category}', ['as' => 'tour.featured', 'uses' => 'PublicController@productList']);
我想在我的产品-list.blade.php视图中显示类别名称 这是我试过的:
{{$_GET['category']}}
这给我错误
Undefined index: category
使用{{request()->route('category')}}
您还差一步:
Route::get('list/{category}', ['as' => 'tour.featured', 'uses' => 'PublicController@productList']);
之后,您必须在 PublicController 中创建 productList 方法,例如
function PublicController(Request $request)
{
echo $request; // will print the data in $product->category
// Now you can pass this value to your view like:
return view('view_name', array('category', $product->category));
}
并像这样查看:
{{$_GET['category']}}
使用相同的路线并使您的控制器像:
public function yourMethod($category)
{
// other stuff here, will return value for $category
return view('someview', COMPACT('category'));
}
现在您可以在 blade 文件中使用 $category 值,例如:
{{ $category }}