Commit a8178db3 authored by TTS Tran Viet Anh's avatar TTS Tran Viet Anh

resolve threads

parent 9dbf4827
......@@ -16,93 +16,32 @@ class HomeController extends Controller
*/
public function index()
{
$productCategories = ProductCategory::query()->get();
$productCategories = ProductCategory::query()->where('parent_id', '=', null)->get();
$latestDrops = Product::query()
->with('productAttributes')
->where('status', '=', Product::STATUS_ENABLE)
->statusEnabled()
->latest()
->take(4)
->get();
$products = Product::query()->take(8)->get();
$products = Product::query()->latest()->take(8)->get();
$latestBlogs = Post::query()
->with('user')
->statusPublished()
->latest()
->take(3)
->get();
return view('client.index', compact('latestDrops', 'productCategories', 'products', 'latestBlogs'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function getProductsByCategory(Request $request)
{
$categoryID = $request->productCategoryID;
$cats = ProductCategory::query()
->where('id', '=', $request->cat)
->orWhere('parent_id', '=', $request->cat)
->get('id')
->toArray();
$productsByCategory = Product::query()
->where('product_category_id', '=', $categoryID)
->whereIn('product_category_id', $cats)
->latest()
->take(8)
->get();
......
......@@ -26,4 +26,9 @@ public function user()
{
return $this->belongsTo(User::class);
}
public function scopeStatusPublished($query)
{
return $query->where('status', '=', Post::STATUS_PUBLISHED);
}
}
......@@ -25,4 +25,9 @@ public function productAttributes()
{
return $this->hasMany(ProductAttribute::class);
}
public function scopeStatusEnabled($query)
{
return $query->where('status', '=', Product::STATUS_ENABLED);
}
}
......@@ -107,7 +107,7 @@
type: "GET",
url: "{{ route('productsByCategory') }}",
data: {
productCategoryID: {{ $productCategory->id }},
cat: {{ $productCategory->id }},
},
success: function(data) {
$('#productsByCategory').html(data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment