Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

njhelloworld's avatar

Date from Form datepicker

I'm done creating a datepicker.I want to use the inputs of my datepicker named="dateto" and "datefrom" in my controller if the range selected from the datepicker existed in my database. (I literally dont know what to do after creating the datepicker form, I have an idea of doing it on my controller but I cant search for any step by step solution in this problem).

0 likes
4 replies
njhelloworld's avatar

@jlrdw thanks for the reply, yes but how can we do it in controller?meaning passing the value from Datepicker form to my controller and then output it to the other page? in laravel?

dleroari's avatar
dleroari
Best Answer
Level 2

Here is the approach: (view.blade.php -> web.php -> controller)

Html (viewName.blade.php)

<div class="field-body">
    <div class="field">
        <p class="control">
            <input class="datepicker" type="text" placeholder="Select date" name="dateFrom" >
       </p>
    </div>
</div>

The name="inputName" property allows laravel to know what type of input field you want when using request.

Web.php

    Route::post('/view', 'controllerName@method'); 

controllerName.php

    public function getDate(Request $request){
    
        $date = $request->input('dateFrom');
        dd($date); 

    }

Keep in mind, if you want to pass input fields to controller, you must have the them wrapped inside a form, like this.


<form method="POST" action="/view">

    <!-- Declare input fields -->

</form>

njhelloworld's avatar

@dleroari thank you for making me understand that highly appreciated can I use that $date variable inside the ->where() ?

example:

$date = $request->input('dateFrom'); dd($date);

$variable = DB::table('table_name') ->Where(['time_stamp','<=',$date]) ->get();

What i wanted to do there is arrange/sort and get data based on the $date variable

Please or to participate in this conversation.