html - 我在我的 laravel 项目中使用了一个选择标签,但是当我选择它时,它没有从选项中获取任何值

标签 html laravel eloquent

我正在尝试从选择标签中选择后从数据库中获取数据。

这是我的 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/

相关文章:

javascript - 如何在 window.open() 中发布

Laravel 5.3 护照自定义授权?

php - Laravel 5 验证唯一传递变量占位符

html - 将带有输入组类的可点击图标添加到文本框

html - 不包括子元素边距的 flex 元素周围的 CSS 轮廓?

php - 如何合并和求和具有相同 ID 值的项目的某些值

mysql - 使用 Eloquent whereNotIn 时查询非常慢

php - Laravel Eloquent 查询 'with'

php - withCount 闭包中的 groupBy (Laravel 5.3.26)

jquery - html - 单击时输入无法聚焦