samedi 31 juillet 2021

Check whether particular product is already added by user in Laravel

I have two table

  1. Menu
  2. Products

there structures are:

Menu:

id | product_id | user_id 

Product:

id | title | price

issue is i want to show add button if product is added in menu table by the specific user and if product is already added then i have to show remove button to remove data from menu table instead of add table.

 $product = Product::where(['user_id'=>$userID])->with('ProductImages')->get();
 $menuPlanner=Menu::where(['user_id'=>auth()->user()->id])->get();  
 $html =  view('frontend.dashboard.menu.available_items', ['products'=>$product,'menu_planner'=>$menuPlanner])->render();
 echo json_encode(array('products' => $html));

Is there any way in laravel to achieve this without any loop in view.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire