This repository has been archived on 2026-09-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tutoring/app/Http/Controllers/Admin/TeacherController.php
T
2026-01-14 00:54:08 +00:00

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 we’ll 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!');
}
}