Ronald Zwiers
Ronald Zwiers

Reputation: 840

How to handle date from multiple select fields in laravel 5.2

Currently i have created a form field like this in laravel 5.2:

        <li class="form-input-date">    
            <label>Birthday</label>
            <div id="PersonForm_date_of_birth">
                <div class="style-select">
                    {{ Form::selectRange('day', 1, 31) }}
                </div>

                <div class="style-select">
                    {{ Form::selectMonth('month') }}
                </div>

                <div class="style-select">
                    {{ Form::selectYear('year', 1906, 1996) }}
                </div>
            </div>
        </li>

What is the best way to handle this and add the selected data to a single database (date)field?

Upvotes: 1

Views: 596

Answers (1)

Arthur Samarcos
Arthur Samarcos

Reputation: 3299

You have the Carbon library at your disposal. Try something like this:

$year = \Request::get("year"); \\format YYYY
$month = \Request::get("month"); \\format MM
$day = \Request::get("day"); \\format DD

$yourModel->yourDate = \Carbon\Carbon::createFromDate($year,$month,$day);

Simple as that.

Upvotes: 1

Related Questions