我有路线
Route::get("/prodByCat/{category_id}", "ProductController@productsByCategory")->name("product.productsByCategory");
和功能
public function productsByCategory($category_id){
$products = Product::where('category_id', $category_id)->get();
return view("cat", compact("products"));
我的模板中只有
@extends("index")
@section("content")
@foreach($products as $product)
{{ $product->name }}
@endforeach
@endsection
问题是-引导程序和自定义CSS的链接不会继承。我试图创建另一个控制器和新的模板文件。但是,除了从Route中删除{category_id}之外,其他方法均无效。为什么传递{category_id}与指向CSS文件的链接冲突?
我尝试了composer dump-autoload并重新启动计算机。所有其他模板均正常工作。
My index template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>@yield("title")</title>
@yield("css")
<!-- Bootstrap core CSS -->
<link href="files/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="files/shop-homepage.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
@include("layouts._shopNav")
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-3">
@yield('category')
</div>
<!-- /.col-lg-3 -->
<div class="col-lg-9">
@yield("carousel")
<div class="row">
@yield("content")
</div>
<!-- /.row -->
</div>
<!-- /.col-lg-9 -->
</div>
<!-- /.row -->
</div>
<!-- /.container -->
<!-- Footer -->
<footer class="fixed-bottom py-3 bg-dark">
<div class="container">
<p class="m-0 text-center text-white">Some writing<br></p>
</div>
<!-- /.container -->
</footer>
<!-- Bootstrap core JavaScript -->
<script src="files/jquery/jquery.min.js"></script>
<script src="files/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>
答案 0 :(得分:2)
问题是css文件的路径错误。您可以使用
App\Entity\Product:
product:
name: 'Product # 1'
foreignId: <numberBetween(1,99999)>
bodyHtml: <text(300)>
description: '<paragraph(1)>'
tags: ''
option1: "Size"
option2: "Color"
variants: '@pv{1..2}'
App\Entity\ProductVariant:
pv{1..2}:
name: 'Variant <current()>'
grams: <numberBetween(100, 1000)>
sku: <ean8()>
option1 (unique): <numberBetween(1, 200)>
option2: "<randomElement(['red', 'yellow', 'black', 'green', 'white'])>"
确保路径正确。