请在我的控制器中有一个功能。
我想查询stock表以选择< 代码> product_id code>,在 我的PHP刀片已 strong> p>
基本上,我不希望选择 code>之后,应该转到产品表,向用户显示产品的
NAME code>,而不是
product_id code> 。 p>
public function getStockList()
{
$ stock = DB :: table(“stocks”) - &gt; pluck(“product_id”,“product_id”) - &gt; all();
$ products = DB :: table(“products”) - &gt; pluck(“name”) - &gt; where('id',$ stock);
返回视图('shop。 shop') - &gt; with(['stocks'=&gt; $ stocks,
'stock'=&gt; $ stock,'products'=&gt; $ products]);
}
code> < / pre>
{!! Form :: select
(
'stock',
[''=&gt;'选择'] + $ stock,'',
数组(
'class'=&gt;'form-control',
'id'=&gt;'country',
'style'=&gt;'width:350px;'
)
)!!}
{!! Form :: select
(
'product_id',
[''=&gt;'选择供应商'] + $ products,null,
['class'=&gt;'form-control']
) !!}
code> pre>
product_id code>显示给用户,而是产品名称。 p>
div>
Please, I have a function in my controller.
I want to query the stock table to select the list of product_id
and after select
, it should go to product table to display the NAME
of product to the user instead of product_id
.
public function getStockList()
{
$stock = DB::table("stocks")->pluck("product_id","product_id")->all();
$products = DB::table("products")->pluck("name")->where('id', $stock);
return view('shop.shop')->with(['stocks' => $stocks,
'stock' => $stock, 'products' => $products]);
}
My PHP blade has
{!! Form::select
(
'stock',
['' => 'Select'] +$stock,'',
array(
'class'=>'form-control',
'id'=>'country',
'style'=>'width:350px;'
)
)!!}
{!! Form::select
(
'product_id',
[''=>'Select Supplier'] + $products, null,
['class'=>'form-control']
)!!}
Basically, I don't want product_id
to be displayed to the user but the product name.