How to pass date of birth to database in Laravel?

76
October 20, 2018, at 8:20 PM

I am making signup form in which I am taking date of birth from user but I do not know how to pass it to database.

<div class="form-group row">
<label for="dob" class="col-md-4 col-form-label text-md-right">
{{ __('DOB') }}</label>
<div class="col-md-6 input-group input-group-sm col-4 m-0 ">
<input type="date" name="dob" style="width: 200px;" class="form-control {{ 
$errors->has('date') ? ' is-invalid' : '' }}" id="date" placeholder="" 
required/>
@if ($errors->has('date'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('date') }}</strong>
</span>
@endif
Answer 1

In your view you need to create a valid formular first, I show you a very basic example you have to adept that yourself!

The view would look something like this:

A form which posts the data in this case date_of_birth after clicking on the submit button to this url /post/store

<form action="/post/store" method="post">
    {{ csrf_field() }}
    <input type="text" name="date_of_birth">
    <button class="button" type="submit">
</form>

The route should look something similiar to this:

This route call the store function of the PostController

Route::group(['prefix' => 'post', 'as' => 'post.'], function () {
    // ...
    Route::post('store', ['as' => 'store', 'uses' => 'PostController@store']);
});

In your PostController to get the request from the formular and create a new Post.

class PostController extends Controller
{
    public function store(Request $request)
    {
        Post::create([
            // ... add your other data
            'date_of_birth' => $request->date_of_birth
        ]);
        return redirect()->route('/');
    }
}

Do not forget to add the new data in your model's fillable array:

protected $fillable = [
    'date_of_birth'
];

I expect you to aleady have a proper migration.

I advice you to have a look at the docs, becasue this is pretty basic stuff

READ ALSO
Laravel 5.7 - Filter a paginated query builder by an accessor?

Laravel 5.7 - Filter a paginated query builder by an accessor?

I have a query builder that returns paginated data:

71
when i try to Export it as Excel the merging does not work. How Do i make rows merged in downloaded excel

when i try to Export it as Excel the merging does not work. How Do i make rows merged in downloaded excel

I have merged rows with same values using the below jquery codeIt Works Fine

26
Parallel ajax call for a simple progress bar, not showing the current progress which is inside session variable

Parallel ajax call for a simple progress bar, not showing the current progress which is inside session variable

I am trying to implement a simple progress barIt's loops until a constant number, and I want to see the current number the loop is as progress

63
Symfony choice form with months only

Symfony choice form with months only

I want to create form in Symfony with select field filled by months only

49