是否可以从函数中的模型获取数据?我想从产品模型中获取SupplierID数据。
public function productAjax($id)
{
$product = new Producttext();
$products = $product->productexts($id);
$hitung_products = $products->count();
$suplierproduct = Company::select('id', 'CompanyName')
->where(['id' => $products->SupplierID])
->first();
}
但是,在执行时,出现以下错误。
此集合实例上不存在属性[SupplierID]。
答案 0 :(得分:3)
如果您有产品文本 List<Integer> officialIds = null;
//add values to officialIds
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpEntity<List<Integer>> request = new HttpEntity<List<Integer>>(officialIds,
headers);
ResponseEntity<YourResponseClass[]> responses =
restTemplate.postForEntity("your URL", request , YourResponseClass[].class );
List<YourResponseClass> list = Arrays.asList(responses.getBody());
,那么
ID
OR
$product = Producttext::find($id)
答案 1 :(得分:0)
您应该尝试以下操作:
public function productajax($id)
{
$products = Producttext::where('id',$id)->first();
$suplierproduct = Company::select('id', 'CompanyName')
->where(['id' => $products->SupplierID])
->first();
}