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