-1
所以我是一个编码训练营的学生,刚发布了一个问题,但意识到我给了错误代码片段,并决定删除它并在此处重新发布。
我正在制作一个crossfit web应用程序,并且在通过创建将用户/配置文件关联在一起的模式循环时遇到问题。
这里是我的资源SearchController:PHP laravel控制器
public function index(Request $request)
{
//
//dump($request->user());die();
return view('user.search')
->withUsers(User::all())
->withProfile(Profile::where('user_id', $request->user()->id));
}
,这里是我的blade.php文件:
@foreach($users as $user)
<li class = "list-group-item">
{{$user->id}}:
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal{{$user->id}}">
{{$user->name}}
</button>
<!-- Modal -->
<div class="modal fade" id="myModal{{$user->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"></h4>
</div>
<div class="modal-body">
<ul>
<p>{{$profile->name}}</p>
<img src = "{{$profile->img_link}}" alt = "profile_pic" height="200" width="200">
<li><p><strong>Location: </strong>{{$profile->location}}</p></li>
<li><p><strong>Age: </strong>{{$profile->age}}</p></li>
<li><p><strong>Height: </strong>{{$profile->height}}</p></li>
<li><p><strong>Affiliate: </strong>{{$profile->affiliate}}</p></li>
<li><p><strong>Front Squat: </strong>{{$profile->front_squat}} lbs</p></li>
<li><p><strong>Back Squat: </strong>{{$profile->back_squat}} lbs</p></li>
<li><p><strong>Clean and Jerk: </strong>{{$profile->clean_and_jerk}} lbs</p></li>
<li><p><strong>Snatch: </strong>{{$profile->snatch}} lbs</p></li>
<li><p><strong>Deadlift: </strong>{{$profile->deadlift}} lbs</p></li>
<li><p><strong>Bio: </strong>{{$profile->bio}}</p></li>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-default"><a href="/message">Message</a></button>
</div>
</div>
</div>
</div>
</li>
@endforeach
所以,当你点击一个按钮,模式只带来了从最后一个配置文件中的信息已经进入我的MySQL数据库。任何帮助将不胜感激。
你的模式是使用'$ profile'而不是'$ user',它总是链接到当前用户? –
不要删除旧帖子并重新发布。 –
Mangus我发布了ProfileController部分,而不是SearchController,并打算编辑,但点击删除 –