通过id Laravel获取表行



我有一个关于Laravel的小项目,我想通过id获取表行,并以Popup模式显示。我尝试了"where"条件,但它没有任何响应。如何做到这一点?这是我的数据库表(biniyojan_details([1]:https://i.stack.imgur.com/GVd79.png这是我的密码。。

///控制器///

public function biniyojan_popup_details(Request $request)
{
$biniyojan_popup_details = DB::table('biniyojan_details')
->leftJoin('biniyojan','biniyojan.biniyojan_id','biniyojan_details.biniyojan_id')
->select('biniyojan_details.*','biniyojan.biniyojan_id','biniyojan.date','biniyojan.ab','biniyojan.behora')
->where('biniyojan_details.details_id', '=', 'biniyojan_details.biniyojan_id')
->get();
return response()->json(['biniyojan_popup_details' => $biniyojan_popup_details]);
}

///弹出模式脚本///

<script>
$(document).ready(function() {
$('.view_btn').click(function(e) {
e.preventDefault();

var id = $(this).closest('tr').find('.id').text();
$.ajax({
type: "GET",
url: " {{ route('biniyojan_popup_details') }}",
data: {
'checking_viewbtn': true,
'id': id,
},
//success: function(response){

success: function(data) {
var html = '';
var biniyojan_popup_details = data.biniyojan_popup_details;
if (biniyojan_popup_details.length > 0) {
for (let i = 0; i < biniyojan_popup_details.length; i++) {
html += `

<table id="example" border="1"  style=" width:50% ; " class="table table-hover table-wrapper-scroll-y my-custom-scrollbar">
<thead class="text-white bg-primary" style="font-size: 14px;">
<tr><th>` + biniyojan_popup_details[i]['biniyojan_id'] + `</th>
<th>शिर्षक</th>
<th>डेबिट</th>
<th>क्रेडिट</th>
</tr>
</thead>
<tbody class="text-dark" style="font-size: 14px;">
<tr>
<td>` + biniyojan_popup_details[i]['kriyakalap'] + `</td>
<td id="bujet">` + biniyojan_popup_details[i]['cash'] + `</td>
</tr>
<tr>
<td>` + biniyojan_popup_details[i]['debit_credit_type'] + `</td>
<td></td>
<td id="">` + biniyojan_popup_details[i]['cash'] + `</td>
</tr>
<tr class="text-white bg-secondary" style="font-size: 14px;">
<td style="font-weight:bold;">Total</td>
<td style="font-weight:bold;">` + biniyojan_popup_details[i]['cash'] + `</td>
<td style="font-weight:bold;">` + biniyojan_popup_details[i]['cash'] + `</td>
</tr>
</tbody>
</table>

`;
}
} else {
html += `
<tr>
<td colspan = "9" >  Data not Found! </td> 
</tr>
`;
}
$(".modal-body").html(html);
$('#exampleModalCenter').modal('show');
}
})
});
});
</script>

很抱歉,我修改了select查询,它可以工作了

public function biniyojan_popup_details(Request $request) {
$biniyojan_popup_details = BiniyojanDetails :: where('biniyojan_id',$request->id)->get();
return response()->json(['biniyojan_popup_details' => $biniyojan_popup_details]);
}

最新更新