laravelでregister機能を作っています。
userレコードを作成する際に、固有のIDとは違う10桁の数字を付与したいです。
一番最初のuserには1000000001、2番目のuserには1000000002という風に
1ずつ数値を増やしたいです。
viewにhiddenで値を持たせればよいでしょうか。
その際のcontrollerの処理がよくわかってないです。
html
1<main class="main_auth"> 2 <div class="layout_main"> 3 <div class="area_auth area_register"> 4 <div class="img"> 5 <img src="{{ asset('img/logo_vertical.svg') }}"> 6 </div> 7 <div class="text"> 8 <p class="ttl">{{ __('Make Account') }}</p> 9 </div> 10 <form method="POST" action="{{ route('register') }}" novalidate> 11 @csrf 12 <input type="hidden" name="type" value="normal"> 13 <ul class="list_register"> 14 <li> 15 <article> 16 <p class="ttl_list"> 17 {{ __('Or, Register With Form') }} 18 </p> 19 <div class="cnt"> 20 <small class="attention_required"> 21 {{ __('Register account') }} 22 </small> 23 <ul class="list_form_auth"> 24 <li class="required"> 25 <div class="wrap_input"> 26 <input id="email" type="email" class="@error('email') is-invalid @enderror" name="email" placeholder="{{ __('Enter E-Mail Address') }}" 27 value="{{ old('email') }}" required autocomplete="email" autofocus> 28 @error('email') 29 <span class="invalid-feedback" role="alert"> 30 <strong>{{ $message }}</strong> 31 </span> 32 @enderror 33 </div> 34 </li> 35 <li class="required"> 36 <div class="wrap_input"> 37 <input id="password" type="password" class="@error('password') is-invalid @enderror" name="password" placeholder="{{ __('Enter Password') }}" 38 required autocomplete="new-password"> 39 @error('password') 40 <span class="invalid-feedback" role="alert"> 41 <strong>{{ $message }}</strong> 42 </span> 43 @enderror 44 </div> 45 </li> 46 <li class="required"> 47 <div class="wrap_input"> 48 <div class="wrap_input"> 49 <input id="last_name" type="text" class="@error('last_name') is-invalid @enderror" name="last_name" placeholder="{{ __('Enter last name') }}" 50 value="{{ old('last_name') }}" required autocomplete="last_name"> 51 @error('last_name') 52 <span class="invalid-feedback" role="alert"> 53 <strong>{{ $message }}</strong> 54 </span> 55 @enderror 56 </div> 57 <span class="unit_min"></span> 58 <div class="wrap_input"> 59 <input id="first_name" type="text" class="@error('first_name') is-invalid @enderror" name="first_name" placeholder="{{ __('Enter first name') }}" 60 value="{{ old('first_name') }}" required autocomplete="first_name"> 61 @error('first_name') 62 <span class="invalid-feedback" role="alert"> 63 <strong>{{ $message }}</strong> 64 </span> 65 @enderror 66 </div> 67 </div> 68 </li> 69 </ul> 70 <div class="btnarea_step"> 71 <button type="submit" class="btn_"> 72 {{ __('Register account') }} 73 </button> 74 </div> 75 </div> 76 </article> 77 </li> 78 </ul> 79 </form> 80 </div> 81 </div> 82</main>
php
1<?php 2 3namespace App\Http\Controllers\Auth; 4 5use App\Models\User; 6use App\Http\Controllers\Controller; 7use Illuminate\Support\Facades\Hash; 8use Illuminate\Support\Facades\Validator; 9use Illuminate\Foundation\Auth\RegistersUsers; 10 11class RegisterController extends Controller 12{ 13 /* 14 |-------------------------------------------------------------------------- 15 | Register Controller 16 |-------------------------------------------------------------------------- 17 | 18 | This controller handles the registration of new users as well as their 19 | validation and creation. By default this controller uses a trait to 20 | provide this functionality without requiring any additional code. 21 | 22 */ 23 24 use RegistersUsers; 25 26 /** 27 * Where to redirect users after registration. 28 * 29 * @var string 30 */ 31 protected $redirectTo = '/mypage'; 32 33 /** 34 * Create a new controller instance. 35 * 36 * @return void 37 */ 38 public function __construct() 39 { 40 $this->middleware('guest'); 41 } 42 43 /** 44 * Get a validator for an incoming registration request. 45 * 46 * @param array $data 47 * @return \Illuminate\Contracts\Validation\Validator 48 */ 49 protected function validator(array $data) 50 { 51 return Validator::make($data, [ 52 'last_name' => 'required|string|max:255', 53 'first_name' => 'required|string|max:255', 54 'type' => 'required|string|string|max:20', 55 'email' => 'required|string|email|max:255|unique:users', 56 'password' => 'required|string|min:10', 57 ]); 58 } 59 60 /** 61 * Create a new user instance after a valid registration. 62 * 63 * @param array $data 64 * @return \App\User 65 */ 66 protected function create(array $data) 67 { 68 $user = User::create([ 69 'last_name' => $data['last_name'], 70 'first_name' => $data['first_name'], 71 'email' => $data['email'], 72 'type' => $data['type'], 73 'password' => Hash::make($data['password']), 74 ]); 75 } 76} 77
回答1件
あなたの回答
tips
プレビュー