It looks for a column in your called 0 and it doesn't exist on the table alternaterental_images. Check your query.
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select `id`, `image`, `status`, `house_id` from `alternaterental_images` where (`0` = house_id and `1` = 1))
i have houses and their details. am able to display all the houses in a data table.I have a column in the datable whereby a user clicks and they are redirected to another page with all the house details. in the detail page for each house i want to show images of the house in a jquery datatable.am finding the images using using a relationship and also i have added a house_id in the images table. I have been able to integrate the data table using jquery very well but the problem is in the method at the controller where I want to get the images and display them in the details page.if the house doesn't have images the data table will just show the regular message for datatable "no data available".this is my method in the controller
public function get_extraimages(Request $request,$id)
{
$alternateimages=Alternaterental_image::select('id','image','status','house_id')->where(['house_id',$id])->get(); //am guesin this is there the bug comes from
if($request->ajax()){
$allimages = DataTables::of ($alternateimages)
->addColumn ('status',function($row){
return
'<input class="rentalhousestatus" type="checkbox" checked data-toggle="toggle" data-id="'.$row->id.'" data-on="Active" data-off="Not Active" data-onstyle="success" data-offstyle="danger">';
})
->addColumn ('delete',function($row){
return
'<a href="#" id="deletextraimage" class="btn btn-danger" data-id="'.$row->id.'"><i class="fa fa-trash"></i></a>';
})
->rawColumns(['status','delete'])
->make(true);
return $allimages;
}
return view('Admin.Rental_houses.edit_addimages',compact('alternateimages'));
}
here is my jquery code
$(document).ready(function(){
var roomimgid=$('#images_id').val();
var url = '{{ route("get_extraimages", ":id") }}';
url = url.replace(':id', roomimgid);
var alternateimagestable = $('#rentalhseimages').DataTable({
processing:true,
serverside:true,
reponsive:true,
ajax:
{
url:url,
type: 'get',
dataType: 'json',
data:{
'id':roomimgid
},
},
columns: [
{ data: 'id' },
{ data: 'image',
render: function ( data, type, full, meta, row) {
return "<img src=\"/imagesforthewebsite/alternateimages/small/" + data + "\" height=\"80px\" height=\"80px\"/>"
}
},
{ data: 'status',name:'status',orderable:true,searchable:true },
{ data: 'delete',name:'delete',orderable:false,searchable:false },
],
"fnDrawCallback": function( row ) {
$('.rentalhousestatus')
.prop( 'checked', row.status !== 1 )
.bootstrapToggle();
}
});
});
how can i find the images for that specific house and display them in the datatable.
@stephen waweru You need to pass three parameters in the where clause when using the array syntax.
You may also pass an array of conditions to the where function. Each element of the array should be an array containing the three arguments typically passed to the where method:
$users = DB::table('users')->where([
['status', '=', '1'],
['subscribed', '<>', '1'],
])->get();
Please or to participate in this conversation.