Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

64 lines
1.9 KiB

<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules;
use Illuminate\View\View;
class RegisteredUserController extends Controller
{
/**
* Display the registration view.
*/
public function create(): View
{
return view('auth.register');
}
/**
* Handle an incoming registration request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'username' => ['required', 'string', 'max:50'],
'fullname' => ['required', 'string', 'max:255'],
'nip' => ['required', 'string', 'max:20'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:' . User::class],
'no_hp' => ['required', 'string', 'max:20'],
'divisi' => ['required', 'string', 'max:255'],
'address' => ['required', 'string'],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
$user = User::create([
'username' => $request->username,
'fullname' => $request->fullname,
'nip' => $request->nip,
'email' => $request->email,
'no_hp' => $request->no_hp,
'divisi' => $request->divisi,
'role_id' => 3,
'warehouse_id' => 2,
'address' => $request->address,
'status' => 'aktif',
'password' => Hash::make($request->password),
]);
event(new Registered($user));
Auth::login($user);
return redirect(RouteServiceProvider::HOME);
}
}