[英]Laravel Undefined variable: intent Facade\Ignition\Exceptions\ViewException
[英]Laravel is giving me Facade\Ignition\Exceptions\ViewException Undefined variable: GENERAL_SETTING
這是我的 controller 代碼,用於顯示 GENERAL_SETTING 表中的數據
public function show()
{
// mengambil data dari table GENERAL_SETTING
$GENERAL_SETTING = GeneralSettingModel::all();
// mengirim data GENERAL_SETTING ke view /home
return view('/home',['GENERAL_SETTING' => $GENERAL_SETTING]);
}
這是我認為的代碼(home.blade.php)
<div class="table-responsive">
<table class="table table-bordered">
@foreach($GENERAL_SETTING as $gs)
<thead class="bg-primary">
<tr class="border-1">
<th scope="col" colspan="2" class="border-1">Hardware</th>
<th scope="col" colspan="2" class="border-1">Communication</th>
<th scope="col" class="border-1">Master Clock</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" >IP: {{ $gs->IP_HW }}</td>
<td colspan="2" >SNMP Driver
<br>
Status: Connected
</br>
</td>
<td rowspan="4">IP: IP: {{ $gs->IP_MC }}
<br>
Status: Connecteds
</br>
</td>
</tr>
<tr>
<td colspan="2" >Temperature: 31</td>
<td colspan="2" >Cloud Driver
<br>
URL: <a href="cloud.mqtt.com" target="_blank"> cloud.mqtt.com </a>
</br>
<br>
Status: Connected
</br>
</td>
</tr>
<tr>
<td class="bg-primary">Main</td>
<td class="bg-primary">Backup</td>
<td class="bg-primary">Master Driver</td>
<td class="bg-primary">Slave Driver</td>
</tr>
<tr>
<td>IP: {{ $gs->IP_SERVER1 }}
<br>
Status: Connected
</br>
</td>
<td>IP: {{ $gs->IP_SERVER2 }}
<br>
Status: Connected
</br>
</td>
<td>IP: 192.168.1.15
<br>
Status: Connected
</br>
</td>
<td>IP: 192.168.1.16
<br>
Status: Connected
</br>
</td>
</tr>
</tbody>
@endforeach
</table>
</div>
這是我的路線(web.php)
Auth::routes();
Route::get('/home', 'FEPController@home');
Route::get('/home','GeneralSettingController@show');
Route::get('/home', 'HomeController@index')->name('home');
我在其他文件(例如:dashboard.blade.php)中嘗試該代碼,該代碼可以正常運行。 但是,如果我使用 home.blade.php,則始終會顯示該錯誤。 我應該怎么做才能修復該錯誤? 感謝你。
在您的view()
中,只需刪除/home
中的正斜杠,它應該看起來像這樣
return view('home',['GENERAL_SETTING' => $GENERAL_SETTING]);.
只是一條建議,你的代碼很差,你應該這樣做
Controller
public function show()
{
// mengambil data dari table GENERAL_SETTING
$generalSettings = GeneralSetting::all();
// mengirim data GENERAL_SETTING ke view /home
return view('/home',['generalSettings' => $generalSettings]);
}
刀
@foreach($generalSettings as $gs)
//
@endforeach
更多細節
https://laravel.com/docs/5.7/views
https://www.php-fig.org/psr/psr-2/
希望有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.