有许多技能,列类型为boolean(0,1),由laravel提供 如果技能值等于1且user_id等于1,我想获取列的名称, 没有说列的名称因为他们50技能,我在崇高
尝试了这个<?php
$variable2=App\Skill::where('user_id',Auth::user()->id)
->where('job_id','null')
->get();
?>
@foreach($variable2 as $key1 => $value1)
@if($value1='1')
<span class="tags">{{ $key1 }}</span>
@endif
@endforeach
答案 0 :(得分:1)
好吧,看起来你忘记了,<?php
$userSkills = App\Skill::where('user_id',Auth::user()->id)
->where('job_id','null')
->get();
?>
<!-- loop through a list of user skills (get gives us a set of skills -->
@foreach($userSkills as $skill)
<!-- loop through skill properties -->
@foreach($skill->toArray() as $key => $value)
@if($value)
<span class="tags">{{ $key }}</span>
@endif
@endforeach
@endforeach
返回了一系列技能。你必须使用两个循环。
yaml
答案 1 :(得分:1)
<?php $variable2=App\Skill::where('user_id',Auth::user()->id)
->where('job_id','null')
->where('user_id', 1)
->get();
$skills = $variable2->filter(function ($item) { return $item === 1; })->keys();
?>
@foreach($skills as $key)
<span class="tags">{{ $key }}</span>
@endforeach