私は、ブートキャンプの学生をコーディングしていますが、質問を投稿しましたが、間違ったコードのスニペットを与え、そのコードを削除して再投稿することにしました。
私はクロスフィット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データベースに入力されています。どんな助けでも大歓迎です。
あなたのモーダルは、常に現在のユーザにリンクされている '$ user'ではなく' $ profile'を使用していますか? –
古い投稿を削除して再投稿しないでください。 –
Mangus私はSearchControllerではなくProfileControllerの部分を投稿しました。編集はヒットしましたが削除を打つことを意味します。 –