我正在使用路由从视图A
向视图B
发送外键
Route::post('/ultm', function(){
$v = Input::get('v');
if($v != ""){
$movimentacoes = Movimentacoes::where('id_coop', '=' . $v)
->get();
if(count($movimentacoes) > 0)
return view ('movs.index')->withDetails($movimentacoes)->withQuery($v);
}
return view ('movs.index')->withMessage("No data found");
});
这是视图A
中负责发送外键的表单
<form action="/ultm" method="POST">
@csrf
<div class="input-group">
<input type="hidden" class="form-control" name="v" value={{$cooperado->id}}>
<button type="submit" class="btn btn-primary">
<span>Ultimas movimentações</span>
</button>
</span>
</div>
</form>
所以我试图在视图B
上显示该特定键的所有记录
@if(isset($details))
@foreach($details as $mov)
<tr>
<td>{{$mov->idMov}}</td>
<td>{{$mov->id_coop}}</td>
<td>{{$mov->valor}}</td>
<td>{{$mov->created_at}}</td>
<!--<td><a href="{{ route('movs.edit',$mov->idMov)}}" class="btn btn-primary">Edit</a></td>
<td>
<form action="{{ route('movs.destroy', $mov->idMov)}}" method="post">
@csrf
@method('DELETE')
<button class="btn btn-danger" type="submit">Delete</button>
</form>-->
</td>
</tr>
@endforeach
@endif
$mov->id_coop
是$cooperado->id
的外键,我不知道为什么看到B
视图正在获取外键还是不起作用
答案 0 :(得分:1)
您应该做的是:
Route::post('/ultm', function(){
$v = Input::get('v');
if($v != ""){
$movimentacoes = Movimentacoes::where('id_coop', '=' . $v)
->get();
if(count($movimentacoes) > 0)
$data['details']=$movimentacoes;
return view ('movs.index',$data)->withDetails($movimentacoes)->withQuery($v);
}
return view ('movs.index')->withMessage("No data found");
});