我收到此錯誤:未定義變數:sales_rep_names(查看:C:\wamp64\www\VLCMRenewals\resources\views\search\index.blade.php)
當我嘗試在刀片中添加新的搜索下拉串列時。這是我添加的導致問題的新代碼:
{{--select Sales Representative --}}
<!-- adding sales rep placeholder
Can we make this a drop-down menu?
need to make sure "name=" is correct -->
<div class="form-group col-md-4">
<label class="mr-sm-2" >Sales Representative</label>
<select class="custom-select mr-sm-2" name="primary_sales_rep">
<option selected></option>
@if(count($sales_rep_names) >0)
@foreach ($sales_rep_names as $sales_rep_name)
<option value='{{$sales_rep_name->Primary_Sales_Rep}}'>{{$sales_rep_name->Primary_Sales_Rep}}</option>
@endforeach
@endif
</select>
</div>
這是一個有效的下拉串列示例(我復制了格式):
{{--select Manufacturer --}}
<div class="form-group col-md-4" >
<label class="mr-sm-2" >Manufacturer Name</label>
<select class="custom-select mr-sm-2" name="company">
<option selected></option>
@if(count($manufacturer_names) >0)
@foreach ($manufacturer_names as $manufacturer_name)
<option value='{{$manufacturer_name->Manufacturer_Name}}'>{{$manufacturer_name->Manufacturer_Name}}</option>
@endforeach
@endif
</select>
</div>
最后,這是我在 Controller 中的代碼(制造商和客戶都作業):
public function index()
{
// will need to add Sales Rep here
$customer_names = DB::table('dbo.contract_view')
->distinct()
->orderBy('Customer_Name','asc')
->get(['Customer_Name']);
$manufacturer_names = DB::table('dbo.contract_view')
->distinct()
->orderBy('Manufacturer_Name','asc')
->get(['Manufacturer_Name']);
// when I tested with product part number it also gave me an error with index.blade.php. maybe this is the wrong spot?
$sales_rep_names = DB::table('dbo.contract_view')
->distinct()
->orderBy('Primary_Sales_Rep','asc')
->get(['Primary_Sales_Rep']);
return view('search.index', ['customer_names' => $customer_names], ['manufacturer_names' => $manufacturer_names], ['sales_rep_names' => $sales_rep_names]);
}
有什么建議嗎?
uj5u.com熱心網友回復:
您將變數作為用逗號分隔的 3 個不同陣列發送。視圖引數是$view, $data, $mergeData,因此您發送的第四個引數將被忽略。
將變數傳遞給視圖的正確方法是這樣的:
return view('search.index', [
'customer_names' => $customer_names,
'manufacturer_names' => $manufacturer_names,
'sales_rep_names' => $sales_rep_names
]);
要么
return view('search.index')
->with(compact('customer_names', 'manufacturer_names', 'sales_rep_names');
要么
return view('search.index')
->with('customer_names', $customer_names)
->with('manufacturer_names', $manufacturer_names)
->with('sales_rep_names', $sales_rep_names)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/445664.html
