我知道这是一个简单的问题,但为什么我会多次获得相同的记录?我尝试使用dd($data)
,它向我展示了多个相同的记录。我做错了什么?
profile.blade.php
@foreach($data as $value)
<tr>
@if($value->Evaluation_Status == 'No')
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
@elseif(($value->blacklist == 'Yes') && ($value->name == $value->Name))
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
@else
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
@endif
<th>
{{$value->Evaluation_Status}}
</th>
<th>{{ \Carbon\Carbon::parse($value->created_at)->format('d/m/Y')}}</th>
<th><form action="{{ url('/home/'.$value->pi_id.'/delete') }}" method="get">
{{ csrf_field() }}
<button type="submit">Delete</button>
</form></th>
</tr>
@endforeach
Controller.php这样
$data = DB::table('personal_infos')
->select('personal_infos.id as pi_id','personal_infos.Name','verifications.name','verifications.blacklist','evaluations.Evaluation_Status', 'evaluations.created_at')
->join('verifications','verifications.id','=','verifications.id')
->join('evaluations', 'evaluations.user_id', '=', 'personal_infos.id')
->where('personal_infos.deleted_at', NULL)
->orderBy('personal_infos.created_at', 'desc')
->get();
return view('home',compact('data'));
答案 0 :(得分:1)
通过更改
解决了问题->join('verifications','verifications.id','=','verifications.id')
到
->join('verifications','verifications.id','=','personal_infos.id')
Controller.php 中的