tutoring/app/Http/Controllers/Admin/TeacherController.php

70 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
use App\Models\TeacherProfile;
use App\Models\Subject;
use App\Models\Level;
class TeacherController extends Controller
{
public function index()
{
$teachers = \App\Models\TeacherProfile::with('user')->get();
return view('admin.teachers.index', compact('teachers'));
}
public function create()
{
$subjects = Subject::orderBy('name')->get();
$levels = Level::orderBy('name')->get();
return view('admin.teachers.create', compact('subjects', 'levels'));
}
public function store(Request $request)
{
// Later well add validation here
// Create the User
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
$user->assignRole('teacher');
// Handle profile picture upload (placeholder for now)
$pathToFile = null;
if ($request->hasFile('picture')) {
$pathToFile = $request->file('picture')->store('teacher_pictures', 'public');
}
// Create the TeacherProfile
$teacher = TeacherProfile::create([
'user_id' => $user->id,
'bio' => $request->bio,
'location' => $request->location,
'hourly_rate'=> $request->hourly_rate,
'picture' => $pathToFile,
]);
// For later: attach subjects and levels
// $teacher->subjects()->sync($request->subjects);
// $teacher->levels()->sync($request->levels);
// Redirect somewhere (dashboard for now)
return redirect()->route('admin.dashboard')
->with('success', 'Teacher added successfully!');
}
}