出于某种原因,当我尝试为管理员设置上传按钮时,上传按钮没有显示,有人可以看看并告诉我它有什么问题吗?
test.blade.php
@foreach ($data as $object)
<b>Name: </b>{{ $object->Name }}<br><br>
<b>Email: </b>{{$object->Email}}<br><br>
@foreach ($data3 as $currentUser)
<a href="{!! route('user.upload.image', ['user'=>$currentUser->id]) !!}">
<button class="btn btn-primary"><i class ="fa fa-plus"></i>Upload Images</button>
</a>
@endforeach
@endforeach
HomeController(我获取一对一关系的id)
public function getInfo($id) {
$data = personal_info::where('id',$id)->get();
$data3=UserImage::where('user_id',$id)->get();
return view('test',compact('data','data3'));
答案 0 :(得分:1)
在您的控制器中,您将获得所有UserImages
并将其发送到您的视图。
public function getInfo($id) {
$data = personal_info::where('id',$id)->get();
$data3=UserImage::where('user_id',$id)->get();
return view('test',compact('data','data3'));
}
然后,您将遍历该集合,以显示您获得的所有结果的上传按钮。
@foreach ($data as $object)
<b>Name: </b>{{ $object->Name }}<br><br>
<b>Email: </b>{{$object->Email}}<br><br>
@foreach ($data3 as $currentUser)
<a href="{!! route('user.upload.image', ['user'=>$currentUser->id]) !!}">
<button class="btn btn-primary"><i class ="fa fa-plus"></i>Upload Images</button>
</a>
@endforeach
@endforeach
但问题是,如果$data3
UserImages
为空,那么foreach
会被忽略,因为它是空的,并且不会显示您的按钮。
要显示按钮,请确保数据库中包含数据,以使$data3
不为空。