Skip to content

Commit

Permalink
search product by its category and description
Browse files Browse the repository at this point in the history
  • Loading branch information
S4nfs committed Apr 8, 2022
1 parent 4631172 commit 083dc77
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function index()
$data = Product::all();
return view('product', ['products' => $data]);
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function productDetail($id)
{
$data = Product::find($id);
return view('detail', ['product' => $data]);
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function addToCart(Request $req)
{
if ($req->session()->has('user')) {
Expand All @@ -35,13 +35,13 @@ function addToCart(Request $req)
return redirect('/login');
}
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function countCartItem()
{
$userId = Session::get('user')[0]->id;
return Cart::where('user_id', $userId)->count();
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function mycartlist()
{
if (session()->has('user')) {
Expand All @@ -53,21 +53,21 @@ function mycartlist()
return redirect('login');
}
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function removecart($id)
{
Cart::destroy($id);
return redirect('cartlist');
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function checkout()
{
if (session()->has('user')) {
$userId = Session()->get('user')[0]->id;
$products = DB::table('cart')->join('products', 'cart.product_id', '=', 'products.id')->where('cart.user_id', $userId)->sum('products.price');
$getuser = DB::table('users')->where('id', $userId)->get();
$productShowcase = DB::table('cart')->join('products', 'cart.product_id', '=', 'products.id')->where('cart.user_id', $userId)->get('products.*');
return view('order', ["total" => $products, "getuser" => $getuser,"productShowcase" => $productShowcase]);
return view('order', ["total" => $products, "getuser" => $getuser, "productShowcase" => $productShowcase]);
// return ["total" => $products, "getuser" => $getuser, "productShowcase" => $productShowcase];
// return ["total" => $products] ["getuser" => $getuser] ["productShowcase" => $productShowcase];

Expand All @@ -77,7 +77,7 @@ function checkout()
return redirect('login');
}
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function orderPlace(Request $req)
{
if (session()->has('user')) {
Expand All @@ -102,7 +102,7 @@ function orderPlace(Request $req)
return redirect('login');
}
}
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
function myOrders()
{
if (session()->has('user')) {
Expand All @@ -111,4 +111,11 @@ function myOrders()
return view('myorders', ["fetchOrders" => $myorders]);
}
}
//--------------------------------------------------------------------------------------------------------------------
function searchProducts(Request $req)
{
$search = $req->search; //can also use If(request('search'))
$data = Product::Where('category', 'like', '%' . $search . '%')->orWhere('description', 'like', '%' . $search . '%')->get();
return view('searchresults',['sproducts' => $data]);
}
}

0 comments on commit 083dc77

Please sign in to comment.