【发布时间】:2020-12-28 13:27:45
【问题描述】:
我需要制定我的网站导航栏并将其链接到页面。这是一个电子商务网站。每个菜单都有子菜单。这些菜单和子菜单需要根据给定的表格制定。由于这是我的第一个项目,因此有点难以理解如何整理它。
这意味着,我的菜单需要加载为台式机、笔记本电脑、打印机和扫描仪等。并且作为笔记本电脑的子菜单hp,而 dell 需要使用该 category_id 和 parent_id 加载。
这是我的刀片文件。
<div class="hs-mega-menu vmm-tfw u-header__sub-menu" aria-labelledby="basicMegaMenu">
<div class="row">
<div class="row u-header__mega-menu-wrapper">
<div class="col mb-3 mb-sm-0">
<span class="u-header__sub-menu-title">Desktops</span>
<ul class="u-header__sub-menu-nav-group mb-3">
<li>
<a class="nav-link u-header__sub-menu-nav-link" href="#" class="font-size-15 text-gray-90">HP</a>
</li>
<li>
<a class="nav-link u-header__sub-menu-nav-link" href="#" class="font-size-15 text-gray-90">DELL</a>
</li>
<li>
<a class="nav-link u-header__sub-menu-nav-link" href="#" class="font-size-15 text-gray-90">ACER</a>
</li>
<li>
<a class="nav-link u-header__sub-menu-nav-link" href="#" class="font-size-15 text-gray-90">ASUS</a>
</li>
</ul>
</div>
</div>
</div>
</div>
这是我的控制器。
HomeController
class HomeController extends Controller
{
public function index()
{
return view('home');
}
public function landing_page()
{
$features = Feature::get();
$products = Product::get();
return view ('index',compact('products', 'features'));
}
public function products(Request $request, $cat_name)
{
$category= Category::with('products')->find($cat_name);
return view('index')->with(compact('products'));
}
}
这是我的产品表。
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('prod_name');
$table->string('prod_brand')->nullable();
$table->unsignedBigInteger('category_id');
$table->string('prod_description')->nullable();
$table->string('prod_item_code')->nullable();
$table->string('prod_modal')->nullable();
$table->string('prod_size')->nullable();
$table->string('prod_weight')->nullable();
$table->string('prod_height')->nullable();
$table->string('prod_manufacturer')->nullable();
$table->float('prod_price')->nullable();
$table->float('prod_discount')->nullable();
$table->float('prod_quantity')->nullable();
$table->string('prod_image_path')->nullable();
$table->timestamps();
$table->foreign('category_id')
->references('id')
->on('categories')
->onDelete('cascade');
});
}
这是我的类别表。
public function up()
{
Schema::create('categories', function (Blueprint $table)
{
$table->bigIncrements('id');
$table->unsignedBigInteger('parent_id')->nullable();
$table->string('cat_name')->nullable();
$table->string('cat_image_path')->nullable();
$table->timestamps();
});
}
这是我的路线。
Route::get('/index', 'HomeController@categories')->name('index');
【问题讨论】:
标签: php laravel navigation e-commerce menubar