title: HasMany relationship doesn't work in Laravel
body: <p>I have registration form generated through php artisan make:auth command in Laravel project. I want to customize it a bit by adding functionality that user can select his/her gender when registering. I made genders table that has genders column with two values Man and Woman and also added gender_id column in users table. I hasMany relationship but when I try and register user he is registered but gender_id columns is still NULL. I don't know where the mistake is. Any help is appreciated. Here is my code. </p>
  
  <p>RegisterController.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\Auth;
  
  use App\Gender;
  use App\User;
  use App\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Hash;
  use Illuminate\Support\Facades\Validator;
  use Illuminate\Foundation\Auth\RegistersUsers;
  
  class RegisterController extends Controller
  {
      /*
      |--------------------------------------------------------------------------
      | Register Controller
      |--------------------------------------------------------------------------
      |
      | This controller handles the registration of new users as well as their
      | validation and creation. By default this controller uses a trait to
      | provide this functionality without requiring any additional code.
      |
      */
  
      use RegistersUsers;
  
      protected $redirectTo = '/home';
  
  
      public function __construct()
      {
          $this-&gt;middleware('guest');
      }
  
      protected function validator(array $data)
      {
          return Validator::make($data, [
              'genders' =&gt; ['required', 'string', 'max:255'],
              /* 'gender_id' =&gt; 'required|exists:mysql.genders,id', */
              'name' =&gt; ['required', 'string', 'max:255'],
              'email' =&gt; ['required', 'string', 'email', 'max:255', 'unique:users'],
              'age' =&gt; ['required', 'integer', 'min:18'],
              'password' =&gt; ['required', 'string', 'min:8', 'confirmed'],
          ]);
      }
  
      protected function create(array $data)
      {
          $genders = Gender::where('genders', request()-&gt;genders)-&gt;get()-&gt;pluck('id')-&gt;first();
  
          $user = User::create([
              'genders_id' =&gt; $genders,
              'name' =&gt; $data['name'],
              'email' =&gt; $data['email'],
              'age' =&gt; $data['age'],
              'password' =&gt; Hash::make($data['password']),
          ]);
  
          return $user;
      }
  }
  </code></pre>
  
  <p>register.blade.php</p>
  
  <pre><code>@extends('layouts.app')
  
  @section('content')
  &lt;div class="container"&gt;
      &lt;div class="row justify-content-center"&gt;
          &lt;div class="col-md-8"&gt;
              &lt;div class="card"&gt;
                  &lt;div class="card-header"&gt;{{ __('Register') }}&lt;/div&gt;
  
                  &lt;div class="card-body"&gt;
                      &lt;form method="POST" action="{{ route('register') }}"&gt;
                          @csrf
  
  
  
  
                          &lt;div class="form-group row"&gt;
                              &lt;label for="genders" class="col-md-4 col-form-label text-md-right"&gt;{{ __('Genders') }}&lt;/label&gt;
                              &lt;div class="col-md-6"&gt;
  
  
   &lt;select id="genders" class="form-control @error('genders') is-invalid @enderror" name="genders" value="{{ old('genders') }}" required autocomplete="genders"&gt;
  
  
                                      &lt;option value="Woman"&gt;Woman&lt;/option&gt;
                                      &lt;option value="Man"&gt;Man&lt;/option&gt;
                                  &lt;/select&gt;
                                  @error('genders')
                                      &lt;span class="invalid-feedback" role="alert"&gt;
                                          &lt;strong&gt;{{ $message }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @enderror
                              &lt;/div&gt;
                          &lt;/div&gt;
  
  
  
  
                          &lt;div class="form-group row"&gt;
                              &lt;label for="name" class="col-md-4 col-form-label text-md-right"&gt;{{ __('Name') }}&lt;/label&gt;
  
                              &lt;div class="col-md-6"&gt;
                                  &lt;input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus&gt;
  
                                  @error('name')
                                      &lt;span class="invalid-feedback" role="alert"&gt;
                                          &lt;strong&gt;{{ $message }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @enderror
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group row"&gt;
                              &lt;label for="email" class="col-md-4 col-form-label text-md-right"&gt;{{ __('E-Mail Address') }}&lt;/label&gt;
  
                              &lt;div class="col-md-6"&gt;
                                  &lt;input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email"&gt;
  
                                  @error('email')
                                      &lt;span class="invalid-feedback" role="alert"&gt;
                                          &lt;strong&gt;{{ $message }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @enderror
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group row"&gt;
                              &lt;label for="age" class="col-md-4 col-form-label text-md-right"&gt;{{ __('Age') }}&lt;/label&gt;
  
                              &lt;div class="col-md-6"&gt;
                                  &lt;select id="age" class="form-control @error('age') is-invalid @enderror" name="age" value="{{ old('age') }}" required autocomplete="age"&gt;
                                      &lt;option value="18"&gt;18&lt;/option&gt;
                                      &lt;option value="19"&gt;19&lt;/option&gt;
                                      &lt;option value="20"&gt;20&lt;/option&gt;
                                      &lt;option value="21"&gt;21&lt;/option&gt;
                                  &lt;/select&gt;
                                  @error('age')
                                      &lt;span class="invalid-feedback" role="alert"&gt;
                                          &lt;strong&gt;{{ $message }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @enderror
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group row"&gt;
                              &lt;label for="password" class="col-md-4 col-form-label text-md-right"&gt;{{ __('Password') }}&lt;/label&gt;
  
                              &lt;div class="col-md-6"&gt;
                                  &lt;input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password"&gt;
  
                                  @error('password')
                                      &lt;span class="invalid-feedback" role="alert"&gt;
                                          &lt;strong&gt;{{ $message }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @enderror
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group row"&gt;
                              &lt;label for="password-confirm" class="col-md-4 col-form-label text-md-right"&gt;{{ __('Confirm Password') }}&lt;/label&gt;
  
                              &lt;div class="col-md-6"&gt;
                                  &lt;input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password"&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group row mb-0"&gt;
                              &lt;div class="col-md-6 offset-md-4"&gt;
                                  &lt;button type="submit" class="btn btn-primary"&gt;
                                      {{ __('Register') }}
                                  &lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  @endsection
  </code></pre>
  
  <p>User.php</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Contracts\Auth\MustVerifyEmail;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  use Illuminate\Notifications\Notifiable;
  
  class User extends Authenticatable
  {
      use Notifiable;
  
      /**
      * The attributes that are mass assignable.
      *
      * @var array
      */
      protected $fillable = [
          'gender_id', 'name', 'email', 'password', 'age',
      ];
  
      /**
      * The attributes that should be hidden for arrays.
      *
      * @var array
      */
      protected $hidden = [
          'password', 'remember_token',
      ];
  
      /**
      * The attributes that should be cast to native types.
      *
      * @var array
      */
      protected $casts = [
          'email_verified_at' =&gt; 'datetime',
      ];
  
      public function genders()
      {
          return $this-&gt;belongsTo(Gender::class);
      }
  }
  </code></pre>