Laravel Eloquent获取比较正确的数据

假冒

我正在为一家时尚商店创建一个迷你库存库存。我正在将Laravel / Voyager与BREAD结合使用,一切都很好。我有2个表,Sizes并且Products有一个共同的列product_code

我想从Sizescolumn product_code=那里得到结果Product 'product_code'我在控制器中有以下查询:

$product_code = Product::all();
$allSizes = Size::where('product_code', ($product_code->product_code));

在browse.blade.php中,我有:

@foreach ($allSizes as $size)
    <tr>
        <td align="right">{{$size->size_name}}</td>
        <td align="right">{{$size->stock}}</td>
    </tr>
@endforeach 

我猜这where句话没有按预期运行。我想获得对应stock基于product_code从表中的每个大小Sizes

娜伊姆·伊亚兹(Naeem Ijaz)

尝试这个

$product_code = Product::pluck('product_code')->toArray();
$allSizes = Size::whereIn('product_code', $product_code)->get();

并在browser.blade.php中:

@foreach ($allSizes as $size)
    <tr>
        <td align="right">{{$size->size_name}}</td>
        <td align="right">{{$size->stock}}</td>
    </tr>
@endforeach 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章