I am new to Laravel. I am using registerController in Laravel to create users . Users data are stored in Users table.
What I have tried is :
@extends('adminlte::auth.auth-page', ['auth_type' => 'register'])
@php( $login_url = View::getSection('login_url') ?? config('adminlte.login_url', 'login') )
@php( $register_url = View::getSection('register_url') ?? config('adminlte.register_url', 'register') )
@if (config('adminlte.use_route_url', false))
@php( $login_url = $login_url ? route($login_url) : '' )
@php( $register_url = $register_url ? route($register_url) : '' )
@else
@php( $login_url = $login_url ? url($login_url) : '' )
@php( $register_url = $register_url ? url($register_url) : '' )
@endif
@section('auth_header', __('adminlte::adminlte.register_message'))
@section('auth_body')<!-- comment -->
<?php $roles = DB::table('roles')->where('id','>',1)->get(); ?>
<div class="login-form">
<div class="container">
<div class="row ">
<div class="register-box">
<div class="register-box-header">
<p class="login-box-msg">{{!empty($type) && $type == 'Agronamist' ? 'Buyer' : ''}} REGISTRATION FORM</p>
</div>
<div class="register-box-body register_body">
<form method="POST" action="{{ route('register') }}" class="registerForm" enctype="multipart/form-data">
@csrf
@if(empty($type))
<div class="row">
<div class="col-md-12 text-center">
<div class="form-group has-feedback">
<select name="role" class="form-control" onchange='window.location.href=window.location.origin+"/register?role="+$(this).val();' required>
<option value="">Select a Role</option>
@foreach($roles as $role)
<option value="{{$role->id}}" {{(count($_GET)>0 && $_GET['role'] == $role->id) ? 'selected' : ''}}>{{$role->name}} </option>
@endforeach
</select>
</div>
</div>
</div>
@else
<input type="hidden" name="role" value="2">
<input type="hidden" name="type" value="{{$type}}">
@endif
@if(count($_GET)>0 && $_GET['role'] != '')
<?php $states = DB::table('states')->orderBy('name','asc')->get();?>
<div class="row">
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="First Name *" name="first_name" value="{{ old('first_name') }}" required>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Last Name *" name="last_name" value="{{ old('last_name') }}" required>
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email *" required>
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control phoneMask" placeholder="Phone *" name="phone" value="{{ old('phone') }}" required>
<span class="glyphicon glyphicon-phone form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Address *" name="address" value="{{ old('address') }}" required>
<span class="glyphicon glyphicon-map-marker form-control-feedback"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="password" class="form-control @error('password') is-invalid @enderror" name="password" placeholder="Password *" required autocomplete="new-password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
@error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="col-md-6">
<div class="form-group has-feedback">
<input type="password" class="form-control" name="password_confirmation" placeholder="Retype password *" required autocomplete="new-password">
<span class="glyphicon glyphicon-log-in form-control-feedback"></span>
</div>
</div>
<div class="row">
<div class="col-md-3 col-xs-offset-4 submit_btn">
<button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
</div>
</div>
</form>
Register Controller
<?php
namespace AppHttpControllersAuth;
use IlluminateHttpRequest;
use IlluminateAuthEventsRegistered;
use AppHttpControllersController;
use IlluminateDatabaseEloquentBuilder;
use AppUser,AppUserDetails,AppUserRoles,AppUserAddresses, Appmanager_group;
use IlluminateFoundationAuthRegistersUsers;
use IlluminateSupportFacadesHash;
use IlluminateSupportFacadesValidator;
use CarbonCarbon;
use Auth;
use DB;
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = '/';
public function __construct()
{
//$this->middleware('guest');
}
public function register(Request $request){
$this->validator($request->all())->validate();
// dd($this->validator($request->all())->validate());
event(new Registered($user = $this->create($request->all())));
if(array_key_exists('type', $request->all())){
return $this->registered($request, $user) ? : redirect('/buyersList/'.Auth::user()->id)->with('success','Registered successfully.');
}else{
return $this->registered($request, $user) ? : redirect($this->redirectPath())->with('success','Registered successfully. Please wait for the approval to access your account.');
}
}
//$this->guard()->login($user);
protected function validator(array $data)
{
return Validator::make($data, [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'phone' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return AppUser
*/
protected function create(array $data)
{
$user = User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'phone' => $data['phone'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
My data is not inserting to users table,and the create function is not working when I dd($user) it. How to make my code working. What my page shows when I try to submit data is :