<?php

namespace App\Http\Controllers\Auth;

use App\Lecturer;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class LecturerRegisterController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware('guest:lecturer');
    }

    public function showRegistrationForm()
    {
        return view('auth.lecturer-register');
    }

    public function register(Request $request)
    {
        // Validate form data
        $this->validate($request,
            [
                'name' => ['required', 'string', 'max:255'],
                'email' => ['required', 'string', 'email', 'max:255', 'unique:lecturers'],
                'password' => ['required', 'string', 'min:8']
            ]
        );

        // Create lecturer user
        try {
            $lecturer = Lecturer::create([
                'name' => $request->name,
                'email' => $request->email,
                'password' => Hash::make($request->password),
            ]);

            // Log the lecturer in
            Auth::guard('lecturer')->loginUsingId($lecturer->id);
            return redirect()->route('lecturer.dashboard');
        } catch (\Exception $e) {
            return redirect()->back()->withInput($request->only('name', 'email'));
        }
    }
}

{'avg_line_length': 27.07843137254902, 'max_line_length': 90, 'alphanum_fraction': 0.5459811730629979, 'licenses': ['MIT'], 'repository_name': 'HuaLa6564/lar7-svFinder', 'path': 'app/Http/Controllers/Auth/LecturerRegisterController.php', 'size': 1381, 'lang': 'PHP'}