| Server IP : 14.225.204.176 / Your IP : 216.73.216.6 Web Server : nginx/1.24.0 System : Linux nodejs-ybgk 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64 User : root ( 0) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/php/thanhphuong/app/Http/Controllers/Auth/ |
Upload File : |
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Customer;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Validation\Rule;
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;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255|unique:users',
'email' => [
'email',
'max:255',
Rule::unique('users')->where(function ($query) {
return $query->where('is_deleted', false);
}),
],
'password' => 'required|string|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
$data['is_active'] = false;
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone_number'],
'company_name' => $data['company_name'],
'role_id' => $data['role_id'],
'biller_id' => $data['biller_id'],
'warehouse_id' => $data['warehouse_id'],
'is_active' => $data['is_active'],
'is_deleted' => false,
'password' => bcrypt($data['password']),
]);
if($data['role_id'] == 5) {
$data['name'] = $data['customer_name'];
$data['user_id'] = $user->id;
Customer::create($data);
}
return $user;
}
}