繁体   English   中英

Laravel 错误:缺少路由错误所需的参数

[英]Laravel error: Missing required parameters for Route Error

我不断收到此错误

Illuminate \ Routing \ Exceptions \ UrlGenerationException PHP 8.1.1 9.1.0 缺少 [Route: client.brand_clicked] [URI:brands/{brand_id}] [缺少参数:brand_id] 的必需参数。

当我点击我的产品网站时,我遇到了这个错误,因为brand_click侧边栏过滤器按钮

这是我的侧边栏有 route:client.brand_clicked

<div class="h4 col-xs-b25" id="check-brand">Thương Hiệu</div>
    <label class="checkbox-entry">
        @foreach($brands as $brand)
            <a href="{{ route('client.brand_clicked',['brand_id'=>$brand->ma_TH])}}">
                <button class="btn" style="width:98px; margin-bottom:5px;" value = "{{ $brand->ma_TH}}"  name="btn-brand">{{ $brand->ten_TH}}</button>
            </a>
        @endforeach
    </label>
    <div class="empty-space col-xs-b10"></div>

这是我的控制器

public function brand_clicked($brand_id){
    $categories = Category::where('parent_id',0)->get();
    $products = Product::where('brand_id',$brand_id)->paginate(9);
    $brands = DB::table('product')->leftJoin('brands','product.brand_id','=','brands.brand_id')->select('brands.brand_id','brands.brand_name')->groupBy('brands.brand_id','brands.brand_name')->get();
    $total = count($products);
    return view('client.products', compact('categories','brands','products','total'));
}

这是我的路线 - web.php 文件

Route::get('/brands/{brand_id}',[App\Http\Controllers\client\ProductController::class,'brand_clicked'])->name('client.brand_clicked');

我的猜测是这个问题是这一行:

<a href="{{ route('client.brand_clicked',['brand_id'=>$brand->ma_TH])}}">

广告至少有一个 $brand 对象没有“ma_TH”属性。 $brand->ma_TH 为空或为空。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM