mercredi 30 mars 2022

Trying to get data using forgein key Angular

This is laravel function in the controller

public function getcatproduct($id)
    {
        $categories = category::all();
        $products = product::where('category_id', "=", $id)->first();
        // $products = $prod->categories;
        $categories = category::findOrFail($id);
        return response()->json([
            'data' => $categories,
            'data' => $products,
            'message' => 200
        ]);
    }

Typescript code getCatByProduct is a service I'm using laravel as an API !

   ngOnInit(): void {
  
    this.id = this.route.snapshot.paramMap.get('id');
    this.getProductbyCategData();
   
  }

getProductbyCategData(){
    this.dataService.getCatByProduct(this.id).subscribe(res => {
     this.data = res;
     this.product = this.data;
   
    });   }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire