Step 1: tạo route about
- Hiệu chỉnh file
routes/web.php
1Route::get('/san-pham/{id}', 'FrontendController@productDetail')->name('frontend.productDetail');
Step 2: viết code action
Viết code cho action productDetail():
1/**
2 * Action hiển thị chi tiết Sản phẩm
3 */
4public function productDetail(Request $request, $id)
5{
6 $sanpham = SanPham::find($id);
7
8 // Query Lấy các hình ảnh liên quan của các Sản phẩm đã được lọc
9 $danhsachhinhanhlienquan = DB::table('cusc_hinhanh')
10 ->where('sp_ma', $id)
11 ->get();
12
13 // Query danh sách Loại
14 $danhsachloai = Loai::all();
15
16 // Query danh sách màu
17 $danhsachmau = Mau::all();
18
19 return view('frontend.pages.product-detail')
20 ->with('sp', $sanpham)
21 ->with('danhsachhinhanhlienquan', $danhsachhinhanhlienquan)
22 ->with('danhsachmau', $danhsachmau)
23 ->with('danhsachloai', $danhsachloai);
24}
Tạo view resources/views/frontend/pages/product-detail.blade.php
1{{-- View này sẽ kế thừa giao diện từ `frontend.layouts.master` --}}
2@extends('frontend.layouts.master')
3
4{{-- Thay thế nội dung vào Placeholder `title` của view `frontend.layouts.master` --}}
5@section('title')
6Sản phẩm Shop Hoa tươi - Sunshine
7@endsection
8
9{{-- Thay thế nội dung vào Placeholder `custom-css` của view `frontend.layouts.master` --}}
10@section('custom-css')
11@endsection
12
13{{-- Thay thế nội dung vào Placeholder `main-content` của view `frontend.layouts.master` --}}
14@section('main-content')
15
16<!-- Product info -->
17@include('frontend.widgets.product-info', ['sp' => $sp, 'hinhanhlienquan' => $danhsachhinhanhlienquan])
18
19@endsection
20
21{{-- Thay thế nội dung vào Placeholder `custom-scripts` của view `frontend.layouts.master` --}}
22@section('custom-scripts')
23@endsection