tanveerkhanwd
9 months ago

how to search data from more then one field in laravel

Posted 9 months ago by tanveerkhanwd

my view:

        <div class="box-body">
          {{ csrf_field() }}
          <!-- text input -->
          <div class="form-group">
            <div class="col-sm-3">
              {!! Form::text('search','',['class'=>'form-control','placeholder'=>'Search','required'=>'required']); !!}
              <span class="text-danger">{{ $errors->first('search') }}</span>
            </div>
            <div class="col-sm-2">
              {!! Form::submit('search',['class'=>'btn btn-primary']); !!}
              <span class="text-danger">{{ $errors->first('status') }}</span>
            </div>
          </div>
      {!! Form::close() !!} 

My Controller:

public function index(Request $request)
    {
        $search = \Request::get('search');
        
        $records = config('constant.displayPageRecords');
        $admission = Admission::where('name','like','%'.$search.'%')
        ->orderBy('name')->paginate($records);
        return view('admin.admission.index',['admission'=>$admission,'records'=>$records]);
    }

Please sign in or create an account to participate in this conversation.