我正在尝试从选择标签中选择后从数据库中获取数据。
这是我的 View 代码:
<div class="form-row">
<div class="form-group col-md-6">
<label>Name</label>
<select name="id" class="form-control">
@foreach($clients as $client)
<option value="{{ $client->Cid }}" {{ $selectedclients == $client->Cid ? selected="selected" : '' }}>{{ $client->name }}</option>
@endforeach
</select>
</div>
</div>
这是我的 Controller 代码:
$Clients = Client::all();
$selectedClients = Client::first()->Cid;
当我运行我的代码时,出现以下错误:
Syntax error, unexpected '=' (View: /home/prasanna/Billing-master/resources/views/Qtcreate.blade.php).
最佳答案
您忘记了在这一行中围绕 selected="selected"
的引号:
<option value="{{ $client->Cid }}" {{ $selectedclients == $client->Cid ? 'selected="selected"' : '' }}>{{ $client->name }}</option>
关于html - 我在我的 laravel 项目中使用了一个选择标签,但是当我选择它时,它没有从选项中获取任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57196506/