<?php

namespace App\Http\Livewire\Admin\Pages;

use App\Models\Staff;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;

class Staffmanagement extends Component
{
    public function addStaff(Request $request)
    {
        $request->validate([
            'staffName' => 'required',
            'staffUsername' => 'required|unique:staff,username',
            'staffEmail' => 'required|email|unique:staff,email',
            'staffPassword' => 'required',
        ]);
        $newStaff = new Staff();
        $newStaff->name = $request->staffName;
        $newStaff->username = $request->staffUsername;
        $newStaff->email = $request->staffEmail;
        $newStaff->password = Hash::make($request->staffPassword);
        $newStaff->save();
        if($newStaff){
            return redirect()->back()->with('success','Teacher Created Successfully!');
        }else{
            return redirect()->back()->with('error','Teacher Creation Failed!');
        }
    }
    public function render()
    {
        return view('livewire.admin.pages.staffmanagement')->layout('layouts.adminApp');
    }
}
