I have a small project on Laravel and I wanted to fetch table rows by id and display in a Popup modal. I tried 'where' condition but it is not responding anything. How to do that? This is my Database Table (biniyojan_details) [1]: https://i.stack.imgur.com/GVd79.png Here is my code..
///Controller///
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]);
}
///Popup modal script///
<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>