Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5 Laravel编辑表单-选择默认选择_Laravel 5 - Fatal编程技术网

Laravel 5 Laravel编辑表单-选择默认选择

Laravel 5 Laravel编辑表单-选择默认选择,laravel-5,Laravel 5,我正在Laravel中创建一个编辑表单,我想在select下拉列表中选择selected(database)值。我现在做的如下。是正确的方法还是可能有更好的方法?我用的是Laravel 5.4 <select class="form-control" id="type" name="type"> <option value="admin" @if($user->type==='admin') selected='selected' @endif>Admin&l

我正在Laravel中创建一个编辑表单,我想在select下拉列表中选择selected(database)值。我现在做的如下。是正确的方法还是可能有更好的方法?我用的是Laravel 5.4

<select class="form-control" id="type" name="type">
   <option value="admin" @if($user->type==='admin') selected='selected' @endif>Admin</option>
   <option value="telco" @if($user->type==='telco') selected='selected' @endif>Telco</option>
   <option value="operator" @if($user->type==='operator') selected='selected' @endif>Operator</option>
   <option value="subscriber" @if($user->type==='subscriber') selected='selected' @endif>Subscriber</option>
</select>

type==='admin')selected='selected'@endif>admin
type==='telco')selected='selected'@endif>telco
类型==='operator')已选定=='selected'@endif>运算符
type==='subscriber')selected='selected'@endif>subscriber

我认为这是一种正常的方法

如果要使其更“友好”,则需要一些开销,例如,使用@foreach循环来循环一个数组,该数组将为select创建所有选项,如下所示:

$arr = ['admin','telco','operator','subscriber'];

@foreach($arr as $item)
   <option value="{{ $item }}" @if($user->type=== $item) selected='selected' @endif> {{ strtoupper($item) }}</option>
@endforeach
$arr=['admin'、'telco'、'operator'、'subscriber'];
@foreach($arr作为$item)
type==$item)selected='selected'@endif>{{strtoupper($item)}
@endforeach

我认为这是一种正常的方法

如果要使其更“友好”,则需要一些开销,例如,使用@foreach循环来循环一个数组,该数组将为select创建所有选项,如下所示:

$arr = ['admin','telco','operator','subscriber'];

@foreach($arr as $item)
   <option value="{{ $item }}" @if($user->type=== $item) selected='selected' @endif> {{ strtoupper($item) }}</option>
@endforeach
$arr=['admin'、'telco'、'operator'、'subscriber'];
@foreach($arr作为$item)
type==$item)selected='selected'@endif>{{strtoupper($item)}
@endforeach

如果

<select class="form-control" id="type" name="type">
    <option value="admin" {{($user->type ==='admin') ? 'selected' : ''}}> Admin </option>
    <option value="telco" {{($user->type ==='telco') ? 'selected' : ''}}> Telco </option>
    <option value="operator" {{($user->type ==='operator') ? 'selected' : ''}}> Operator </option>
    <option value="subscriber" {{($user->type ==='subscriber') ? 'selected' : ''}}> Subscriber </option>
</select>

类型==='admin')?'已选择“:”}}>Admin
类型==='telco')?'已选择“:”}}>Telco
类型=='operator')?'所选“:”}}>运算符
类型==='subscriber')?'所选“:”}}>订阅服务器

如果

<select class="form-control" id="type" name="type">
    <option value="admin" {{($user->type ==='admin') ? 'selected' : ''}}> Admin </option>
    <option value="telco" {{($user->type ==='telco') ? 'selected' : ''}}> Telco </option>
    <option value="operator" {{($user->type ==='operator') ? 'selected' : ''}}> Operator </option>
    <option value="subscriber" {{($user->type ==='subscriber') ? 'selected' : ''}}> Subscriber </option>
</select>

类型==='admin')?'已选择“:”}}>Admin
类型==='telco')?'已选择“:”}}>Telco
类型=='operator')?'所选“:”}}>运算符
类型==='subscriber')?'所选“:”}}>订阅服务器

这很有道理!这是有道理的!