Step 1: tạo route about
- Hiệu chỉnh file
routes/web.php
php
1Route::get('/san-pham/{id}', 'FrontendController@productDetail')->name('frontend.productDetail');Step 2: viết code action
Viết code cho action productDetail():
php
1/**2 * Action hiển thị chi tiết Sản phẩm3 */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ọc9 $danhsachhinhanhlienquan = DB::table('cusc_hinhanh')10 ->where('sp_ma', $id)11 ->get();12 13 // Query danh sách Loại14 $danhsachloai = Loai::all();15 16 // Query danh sách màu17 $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
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 - Sunshine7@endsection8 9{{-- Thay thế nội dung vào Placeholder `custom-css` của view `frontend.layouts.master` --}}10@section('custom-css')11@endsection12 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@endsection20 21{{-- Thay thế nội dung vào Placeholder `custom-scripts` của view `frontend.layouts.master` --}}22@section('custom-scripts')23@endsection
