jeudi 4 juillet 2019

how to make join in laravel ? get only some columns of another table

I am working on admin panel ... where i get all products from database and show in table ... the problem is i want to get each product categorey from "category" table and get stock of each product from "products attribute" table ... i am create a join but this join collapse product id , name stock or prize from another table... Thanks.

  public function viewProducts(Request $request){
    $products = Product::get();
    $products = Product::join('categories','categories.id','products.category_id')->join('products_attributes','products_attributes.product_id',
        'products.id')->get();
    $products = json_decode(json_encode($products));
    //echo "<pre>"; print_r($products); die;
    return view('admin.products.view_products')->with(compact('products'));
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2RWmylN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire