Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the request values in Laravel

I wish to make search query by datepicker and select field. How could I get the requests values from below view file to controller? Where could I modify in the code? thanks.

index.blade.php

<div class="form-group col-sm-6">
    {!! Form::open(array('class' => 'form', 'method' => 'get', 'url' => url('/pdfs/job_finished_search'))) !!} 
       {!! Form::input('text', 'datepicker_from', null, ['placeholder' => 'Fra', 'id' => 'datepicker_from']) !!}
       {!! Form::input('text', 'datepicker_to', null, ['placeholder' => 'Til', 'id' => 'datepicker_to']) !!} 
       {!! Form::select('customer_name', $jobs->pluck('customer_name', 'customer_name')->all(), null, ['class' => 'form-control']) !!}
       {!! Form::submit('Søke', ['class' => 'btn btn-success btn-sm']) !!} 
    {!! Form::close() !!}
</div>

Controller.php

public function job_finished_search(Request $request, Job $jobs)
{

    $jobs = Job::onlyTrashed()
            ->whereBetween('created_at', array(
              (Carbon::parse($request->input('datepicker_from'))->startOfDay()),
              (Carbon::parse($request->input('datepicker_to'))->endOfDay())))
            ->where('customer_name', 'like', '%'.$request->customer_name.'%')
            ->orderBy('deleted_at', 'desc')
            ->paginate(15);

       if (empty($jobs)){
           Flash::error('Search result not found');
    }

    return view('pdfs.index', ['jobs' => $jobs]); 
}
like image 388
JsWizard Avatar asked Mar 07 '23 16:03

JsWizard


1 Answers

There are multiple way to get the request data e.g to get datepicker_from value you can use any of the below

$request->datepicker_from 
$request->input('datepicker_from')
$request->get('datepicker_from')

choose the one you like the most

refer to https://laravel.com/docs/5.5/requests

like image 110
rchatburn Avatar answered Mar 13 '23 04:03

rchatburn