sameermalikrp's avatar

Pagination error_Method App\Http\Controllers\WorkerController::worker() does not exist

Error found on pagination 1)works fine for the first page other than that if I select 2,3,4.... page it shows " ReflectionException in Route.php line 264: Method App\Http\Controllers\WorkerController::worker() does not exist " and the field value(in this case search string erases on every page load)

function search(Request $request)
    {
        $input=$request->only(['search']);
        if(empty($input['search']))
            return redirect('/workers');
        $input=trim(head($input));
        $head4=' Search Results for "<b>'.$input.'</b>"';

        $all_workers=Worker::where('visa_number', 'LIKE',"%{$input}%")
            ->orWhere('passport_number', 'LIKE',"%{$input}%")
            ->orWhere('mobile_number', 'LIKE',"%{$input}%")
            ->orWhere('name', 'LIKE',"%{$input}%")
            ->orderBy('expiry_date','asc')
            ->paginate(9);

        return view('workers.index', compact('all_workers', 'head4'));
    }
``

HTML is given

@extends('layouts.app')

@section('content')

@if( count($all_workers) ) @foreach($all_workers as $worker) diff( $worker->expiry_date); $days=intval(\Carbon\Carbon::now()->diffInDays($worker->expiry_date)); ?>
                          <div class="panel
                          @if( ($days < 7)  ||(\Carbon\Carbon::now() >=  $worker->expiry_date) )panel-danger new-danger
                          @elseif( (7 <= $days) && ( $days < 15 ) ) panel-warning new-warning
                          @else panel-success new-success
                          @endif">
                                      <div class="panel-heading" role="tab" id="heading{!! $i !!}">
                                          <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{!! $i !!}" aria-expanded="true" aria-controls="collapse{!! $i !!}">
                                          <h4 class="panel-title">
                                                  <div class="btn-group-vertical pull-left col-lg-3">
                                                      Name <b>{{ $worker->name }}</b>
                                                  </div>
                                                  <div class="btn-group-vertical col-lg-offset-2 " id="data">
                                                      Visa <b>{{ ($worker->visa_number) }}</b>
                                                  </div>
                                                  <?php
                                                  $dateofexpiry=Carbon\Carbon::now()->diffForHumans($worker->expiry_date);
                                                  ?>
                                                  <div class="btn-group-vertical pull-right col-lg-3" id="data">
                                                      Remaining <b>{{ str_replace(' before', null, $dateofexpiry) }}</b>
                                                  </div>
                                          </h4>
                                        </a>
                                      </div>
                                  <div id="collapse{!! $i !!}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{!! $i !!}">
                                      <div class="panel-body">
                                          <table class="table borderless">
                                              <tr class="borderless">
                                                  <td class="text-left">Passport Number : <b><large>{{$worker->passport_number}}</large></b></td>
                                                  <td class="text-center">Arrival Date: <b><large>{{ \Carbon\Carbon::parse($worker->arrival_date)->toDateString() }}</large></b></td>
                                                  <td class="text-right">Expiry date: <b><large>{{ \Carbon\Carbon::parse($worker->expiry_date)->toDateString() }}</large></b></td>
                                              </tr>
                                             <tr class="borderless">
                                                  <td class="text-left">Visa Type: <b>
                                                          <large>{{ \App\Http\Controllers\WorkerController::empty_field($worker->visa_type, ' - ') }}</large>
                                                      </b></td>
                                                  <td class="text-center">Job Type: <b>
                                                          <large>{{ \App\Http\Controllers\WorkerController::empty_field($worker->job_type, ' - ') }}</large>
                                                      </b></td>
                                                  <td class="text-right">Mobile Number: <b>
                                                          <large>{{ \App\Http\Controllers\WorkerController::empty_field($worker->mobile_number, ' - ') }}</large>
                                                      </b></td>
                                              </tr>
                                          </table>
                                      </div>
                                      <div class="panel-footer">
                                          <div class="row">

                                              <div class="pull-left text-justify" style="margin-left: 5px">
                                                  <span class="btn btn-default">
                                                      Today( <b style="color: #880000"> <large> {{ Carbon\Carbon::now()->toDateString() }}  </large> </b> )
                                                  </span>
                                              </div>
                                              <div class="pull-right">
                                                  <a href="{{ action('WorkerController@edit',[ $worker->visa_number]) }}"  class="btn btn-primary marg-right">
                                                      <i class="fa fa-btn fa-edit"></i>Edit
                                                  </a>
                                              </div>
                                              <div class="pull-right col-sm-offset-2">
                                                  <a href=""
                                                     class="btn btn-danger marg-right"  data-toggle="modal" data-target="#myModal">
                                                      <i class="fa fa-btn fa-remove"></i>Delete
                                                  </a>
                                              </div>

                                          </div>
                                      </div>
                                  </div>
                              </div>

                      @endforeach
                      <div class=" text-center  form-horizontal">
                          {!! $all_workers->links() !!}
                      </div>
                  @else
                      @if($head4 == ' All Workers ' )
                          <h4 class="text-danger">
                              <i class="fa fa-btn fa-eraser"></i>DataBase is Empty!
                              <a href="{{ action('WorkerController@create') }}">
                                  <i class="fa fa-btn fa-plus-square"></i>add
                              </a>
                          </h4>
                      @elseif( str_contains($head4,' Search Results '))
                          <h4 class="text-danger">
                              <i class="fa fa-btn fa-eraser"></i>No Results Found!
                          </h4>

                      @endif
              @endif
          </div>
    </div>
</div>
Modal -->
  <!-- Modal content-->
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">×</button>
      <h4 class="modal-title">Are you sure?</h4>
    </div>
    <div class="modal-body">
      <p>This operation causes permanent removal of the given record.</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
  </div>

</div>

@endsection ``

0 likes
0 replies

Please or to participate in this conversation.