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 ...@@ -16,93 +16,32 @@ class HomeController extends Controller
*/ */
public function index() public function index()
{ {
$productCategories = ProductCategory::query()->get(); $productCategories = ProductCategory::query()->where('parent_id', '=', null)->get();
$latestDrops = Product::query() $latestDrops = Product::query()
->with('productAttributes') ->with('productAttributes')
->where('status', '=', Product::STATUS_ENABLE) ->statusEnabled()
->latest() ->latest()
->take(4) ->take(4)
->get(); ->get();
$products = Product::query()->take(8)->get(); $products = Product::query()->latest()->take(8)->get();
$latestBlogs = Post::query() $latestBlogs = Post::query()
->with('user') ->with('user')
->statusPublished()
->latest() ->latest()
->take(3) ->take(3)
->get(); ->get();
return view('client.index', compact('latestDrops', 'productCategories', 'products', 'latestBlogs')); 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) 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() $productsByCategory = Product::query()
->where('product_category_id', '=', $categoryID) ->whereIn('product_category_id', $cats)
->latest() ->latest()
->take(8) ->take(8)
->get(); ->get();
......
...@@ -26,4 +26,9 @@ public function user() ...@@ -26,4 +26,9 @@ public function user()
{ {
return $this->belongsTo(User::class); return $this->belongsTo(User::class);
} }
public function scopeStatusPublished($query)
{
return $query->where('status', '=', Post::STATUS_PUBLISHED);
}
} }
...@@ -25,4 +25,9 @@ public function productAttributes() ...@@ -25,4 +25,9 @@ public function productAttributes()
{ {
return $this->hasMany(ProductAttribute::class); return $this->hasMany(ProductAttribute::class);
} }
public function scopeStatusEnabled($query)
{
return $query->where('status', '=', Product::STATUS_ENABLED);
}
} }
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
type: "GET", type: "GET",
url: "{{ route('productsByCategory') }}", url: "{{ route('productsByCategory') }}",
data: { data: {
productCategoryID: {{ $productCategory->id }}, cat: {{ $productCategory->id }},
}, },
success: function(data) { success: function(data) {
$('#productsByCategory').html(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