I have 3 table hosts visitors and visitor_types. I wand to show host name and visitor type in a drop down option button. But I am little bit confused about the controller and route code. I write the code code that is given below but it's show -Undefined variable: host (View: C:\laragon\www\ves\resources\views\admin\visitor.blade.php)
Controller Code: hostController.php
public function optionValue(){
$host = host::all();
return view('admin\visitor', compact('host'));
}
View Code: visitor.blade.php
<div class="form-group">
<label class="control-label col-md-3">Visitor Type
<span class="required" aria-required="true"> * </span>
</label>
<div class="col-md-6">
<div class="input-icon right">
<i class="fa"></i>
<select class="form-control input-medium" name="visitorType">
@foreach($host as $host)
<option value="$visitor->name"></option>
</select>
@endforeach
</div>
</div>
Route code: web.php
Route::get('/vsistor','HostController@optionValue')->name('optionValue');
In visitor table the host_id and vType_id is foreign key from host and visitor_types table. So how can I display Name that come from another table in a drop down button?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire