我正在做一个laravel项目,在将变量从控制器传递到视图时遇到问题:
这是控制器方法:
public function index($id){
$data = [];
$company = DB::table('companies')->where('id',$id)->first();
return view('searchResultAdmin.index', ['company'=>$company, 'Data'=>$data]);
}
这是视图:
{{ Form::open(array('url' => '/SearchResultAdmin', 'method' => 'post')) }}
<div class="radio-buttons display-inline">
<fieldset class="display-inline group1">
<label class="radio-inline">
<input type="radio" name="SearchLocation" id="value1" value="Actuals" checked>Actuals
</label>
<label class="radio-inline">
<input type="radio" name="SearchLocation" id="value2" value="Forecasts">Forecasts
</label>
</fieldset>
{{ Form::hidden('id', ($company->id)) }}
<fieldset class="display-inline">
<label class="radio-inline">
<input type="radio" name="Order" id="value3" value="Ascending" checked>Ascending
</label>
<label class="radio-inline">
<input type="radio" name="Order" id="value4" value="Descending">Descending
</label>
</fieldset>
</div>
<div class="dropdown-header-table display-inline">
<h5>Search By:
<select name="SearchBy">
<option value="Account">Account</option>
<option value="Name">Name</option>
<option value="Year">Year</option>
<option value="Description">Description</option>
<option value="Amount">Amount</option>
</select>
</h5>
</div>
<div class="search-input display-inline">
<div class="table-form-header">
<input type="text" class="form-control" name="SearchInputs" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
{{ Form::close() }}
错误提示:未定义变量公司在视图中
答案 0 :(得分:0)
由于
,您收到错误消息{{ Form::hidden('id', ($company->id)) }}
在返回视图之前,先在您的控制器中添加dd($company)
或dd($company->id)
,然后看看您得到了什么。
祝你好运!