每当我运行我的程序时,我都会收到一个错误“Route [userproductss.prdtview] not defined. (View: D:\xampp\htdocs\E-commerce\resources\views\layouts\includes\top.blade.php)”。代码如下
刀刃:
<ul>
<li class="active"><a href="">Home</a></li>
@foreach($categories as $category)
<li><a href="#">{{$category->cat_name}}</a>
<ul class="dropdown">
@foreach($subcat as $sub_cat)
@if($sub_cat->cat_id == $category->id)
<li><a href="{{ route('userproduct.prdtview',$sub_cat->id) }}"><?php echo $sub_cat->sub_cat_name; ?></a></li>
@endif
@endforeach
</ul>
</li>
@endforeach
</ul>
网页.php
Route::resource('userproduct', 'UserProductController');
控制器:
public function prdtview($id)
{
$data=DB::select('select category.cat_name,product_images.prdt_image,product.prdt_name,product.actual_price from product INNER JOIN category on product.catid = category.id INNER JOIN product_images on product.id = product_images.prdt_id where product.sub_cat_id = $id ');
return view("frontend.product",[
'data' => $data
]);
}
该错误是不言自明的,您尚未为您的prdtview
函数定义路由。请记住,无论何时创建资源控制器并定义其路由,都会自动创建以下带有路由的函数。
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
对于您希望路由使用的任何其他方法,那么您必须创建一个方法,并且必须为它定义一个路由,就像prdtview
您必须明确定义一个路由的函数一样。
Route::get('/prdtview/{id}','UserProductController@prdtview')->name('userproduct.prdtview);
现在,当请求到达此路由时,它将被转发到您的prdtview
函数。
您现在可以在刀片中调用您的路线,例如
route('userproduct.prdtview', ['id' => $sub_cat->id]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句