查询中的问题(订购产品)

Issue in query(ordering products)

我想按价格订购产品,一个 link 从低到高,另一个从高到低,但是在我点击 "low to high" 或 "high to low" 之后,订单没有改变,它保持在同一页面上,但 url 正在更改。 我尝试调试查询并得到:"select * from products where categorie_id = ? order by price asc" 是否意味着它无法从类别 table 中找到 ID? 如果是,我找不到问题所在

这是控制器中的函数:

public function products(Request $request, $category_url, $sort= 'ASC')
{
    Product::getProducts($category_url, self:: $data);

    if ( $category1 = Categorie::where('url', '=', $category_url)->first() ) {

        $products = Product::where('categorie_id', $category1->getAttribute('id'))->orderBy('price', $sort)->get();

        return view('content.products', self::$data , compact('products', 'sort')); 
    }
}

这是路线:

  Route::get('shop/{category_url}/sorting-{sort?}', 'ShopController@products');

这些是link的观点,观点是content.products

  <a href="  {{ url('shop/'.$category['url'].'/sorting-asc')}}" style="color:black"> High to low</a> |
  <a href="  {{ url('shop/'.$category['url'].'/sorting-desc')}}" style="color:black">Low to high</a>

模特:

class Product extends Model {


static public function getProducts($category_url, &$data){

    $data['products']=$data['category']=[];


    if ($category=Categorie::where('url','=', $category_url)->first()){

        $category= $category->toArray();
        $data['category']=$category;
        $data['title']=$data['title']. ' | ' . $category['title'];


        if ($products=Categorie::find( $category['id'])->products){

            $data['products']= $products->toArray();
        }
    }
}

我会这样做:

public function products(Request $request, $category_url, $sort= 'ASC'){

    $category1 = Categorie::where('url', '=', $category_url)->first();
    $products = Product::where('categorie_id', $category1->id)->orderBy('price', $sort)->get();
    return view('content.products', ['products' => $products, 'sort' => $sort, 'category' => $category1]); 
}