Wow @Cronix thanks a lot well worked thank you soo much
another small doubt in this itself pagination problm,
this is my controller,
public function index()
{
$sales = Sales_details::orderBy('created_at','desc')- >paginate(5);
return view('Sales_details.view')->withsales($sales);
}
When i click view menu the index function is called and the below given view.blade file will run. there i displayed all the data in tabular format with pagination(5)
here is my view. blade below
@extends('main')
@section('title','| All data Sales')
@section('content')
<div class="row">
<div class="col-md-12">
<table id="sales_details" class="table table-bordered">
<thead>
<th > {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_sid','name'=>'search_sid')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_date','name'=>'search_date')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_time','name'=>'search_time')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_id','name'=>'search_id')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_type','name'=>'search_type')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_name','name'=>'search_name')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_area','name'=>'search_area')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_booth','name'=>'search_booth')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_rl','name'=>'search_rl')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_nl','name'=>'search_nl')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_total','name'=>'search_total')) }}</th>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_note','name'=>'search_note')) }}</th>
<th> <a href="" class="btn btn-success btn-sm" style="width: 100%;">Search</a></th>
</thead>
<thead>
<th >Sales Id</th>
<th>Date</th>
<th>Time</th>
<th>Customer Id</th>
<th>Customer Type</th>
<th>Customer Name</th>
<th>Customer Area</th>
<th>Customer Booth</th>
<th>Rate/Litre</th>
<th>No of Litres</th>
<th>Total</th>
<th>Note</th>
<th>Action</th>
</thead>
<tbody>
@foreach($sales as $sal)
<tr>
{{-- <th>{{ $ven->id }}</th> --}}
<td>{{ $sal->sales_id }}</td>
<td>{{ $sal->date }}</td>
<td>{{ $sal->time }}</td>
<td>{{ $sal->customer_id }}</td>
<td>{{ $sal->customer_type }}</td>
<td>{{ $sal->customer_name }}</td>
<td>{{ $sal->customer_area }}</td>
<td>{{ $sal->customer_booth }}</td>
<td>{{ $sal->rate_per_litre }}</td>
<td>{{ $sal->no_of_litre }}</td>
<td>{{ $sal->total }}</td>
<td>{{ $sal->note }}</td>
<td>
<a href="{{ route('Sales_details.show',$sal->id) }}" class="btn btn-success btn-sm" style="width: 100%;">View</a>
</td>
{!! Form::close() !!}
</tr>
@endforeach
</tbody>
</table>
<div class="text-center">
{!! $sales->Links(); !!}
</div>
</div>
</div>
<script type="text/javascript">
$('#search_sid,#search_date,#search_time,#search_id,#search_type,#search_name,#search_area,#search_booth,#search_rl,#search_nl,#search_total,#search_note').on('keyup',function(){
$.ajax({
type : 'get',
url : '{{URL::to('search_name')}}',
data:{ 'search_sid': $('#search_sid').val(),
'search_date': $('#search_date').val(),
'search_time': $('#search_time').val(),
'search_id': $('#search_id').val(),
'search_type': $('#search_type').val(),
'search_name': $('#search_name').val(),
'search_area': $('#search_area').val(),
'search_booth': $('#search_booth').val(),
'search_rl': $('#search_rl').val(),
'search_nl': $('#search_nl').val(),
'search_total': $('#search_total').val(),
'search_note': $('#search_note').val()
},
success:function(data){
$('tbody').html(data);
}
});
})
</script>
@endsection
When onkeyup event occurs in text box then the search_name function in my controller is called..
This is my search_name function in controller
public function search_name( Request $request )
{
$output="";
$sales = Sales_details::where(function ($query) use ($request)
{
// Sales id.
if (!empty($request->search_sid)) {
$query->Where('sales_id', 'LIKE', '%' . $request->search_sid . '%');
}
// date.
if (!empty($request->search_date)) {
$query->Where('date', 'LIKE', '%' . $request->search_date . '%');
}
// time.
if (!empty($request->search_time)) {
$query->Where('time', 'LIKE', '%' . $request->search_time . '%');
}
// customer id.
if (!empty($request->search_id)) {
$query->Where('customer_id', 'LIKE', '%' . $request->search_id . '%');
}
// type.
if (!empty($request->search_type)) {
$query->Where('customer_type', 'LIKE', '%' . $request->search_type . '%');
}
// Name.
if (!empty($request->search_name)) {
$query->Where('customer_name', 'LIKE', '%' . $request->search_name . '%');
}
// Area.
if (!empty($request->search_area)) {
$query->Where('customer_area', 'LIKE', '%' . $request->search_area . '%');
}
// Booth.
if (!empty($request->search_booth)) {
$query->orWhere('customer_booth', 'LIKE', '%' . $request->search_booth . '%');
}
// rate per litre.
if (!empty($request->search_rl)) {
$query->Where('rate_per_litre', 'LIKE', '%' . $request->search_rl . '%');
}
// No of litres.
if (!empty($request->search_nl)) {
$query->Where('no_of_litre', 'LIKE', '%' . $request->search_nl . '%');
}
// total.
if (!empty($request->search_total)) {
$query->Where('total', 'LIKE', '%' . $request->search_total . '%');
}
// note.
if (!empty($request->search_note)) {
$query->Where('note', 'LIKE', '%' . $request->search_note . '%');
}
})->get();
if($sales)
{
foreach ($sales as $key => $sale)
{
$output.='<tr>'.
'<td>'.$sale->sales_id.'</td>'.
'<td>'.$sale->date.'</td>'.
'<td>'.$sale->time.'</td>'.
'<td>'.$sale->customer_id.'</td>'.
'<td>'.$sale->customer_type.'</td>'.
'<td>'.$sale->customer_name.'</td>'.
'<td>'.$sale->customer_area.'</td>'.
'<td>'.$sale->customer_booth.'</td>'.
'<td>'.$sale->rate_per_litre.'</td>'.
'<td>'.$sale->no_of_litre.'</td>'.
'<td>'.$sale->total.'</td>'.
'<td>'.$sale->note.'</td>'.
'<td>'
."<a href='' class='btn btn-success btn-sm' style='width: 100%;'>View</a>".
'</td>'.
'</tr>';
}
return Response($output);
}
}
now based on my where query the results are filtered so here i need to give pagination what should i do??
if i give pagination(2) in this below line, it doesnt work why?
$sales = Sales_details::where(function ($query) use ($request) {
//those if condition with where clause
})->Paginate(2);
Someone help me in this pagination problem pleasee