diff --git a/app/Http/Controllers/Backend/Instructors/InstructorController.php b/app/Http/Controllers/Backend/Instructors/InstructorController.php index 8cbd552..572891a 100644 --- a/app/Http/Controllers/Backend/Instructors/InstructorController.php +++ b/app/Http/Controllers/Backend/Instructors/InstructorController.php @@ -5,6 +5,10 @@ use App\Http\Controllers\Controller; use App\Models\Instructor; use Illuminate\Http\Request; +use App\Models\Role; +use Illuminate\Support\Facades\Hash; +use Exception; +use File; class InstructorController extends Controller { @@ -13,7 +17,8 @@ class InstructorController extends Controller */ public function index() { - // + $instructor = Instructor::paginate(10); + return view('backend.instructor.index', compact('instructor')); } /** @@ -21,7 +26,8 @@ public function index() */ public function create() { - // + $role = Role::get(); + return view('backend.instructor.create', compact('role')); } /** @@ -29,7 +35,33 @@ public function create() */ public function store(Request $request) { - // + try { + $instructor = new Instructor; + $instructor->name_en = $request->fullName_en; + $instructor->name_bn = $request->fullName_bn; + $instructor->contact_en = $request->contactNumber_en; + $instructor->contact_bn = $request->contactNumber_bn; + $instructor->email = $request->emailAddress; + $instructor->role_id = $request->roleId; + $instructor->bio = $request->bio; + $instructor->status = $request->status; + $instructor->password = Hash::make($request->fullName_bn); + $instructor->language = 'en'; + $instructor->access_block = $request->access_block; + + if ($request->hasFile('image')) { + $imageName = rand(111, 999) . time() . '.' . $request->image->extension(); + $request->image->move(public_path('uploads/instructors'), $imageName); + $instructor->image = $imageName; + } + if ($instructor->save()) + return redirect()->route('instructor.index')->with('success', 'Data Saved'); + else + return redirect()->back()->withInput()->with('error', 'Please try again'); + } catch (Exception $e) { + dd($e); + return redirect()->back()->withInput()->with('error', 'Please try again'); + } } /** @@ -59,8 +91,16 @@ public function update(Request $request, Instructor $instructor) /** * Remove the specified resource from storage. */ - public function destroy(Instructor $instructor) + public function destroy($id) { - // + $data=Instructor::findOrFail(encryptor('decrypt',$id)); + $image_path=public_path('uploads/instructors').$data->image; + + if($data->delete()){ + if(File::exists($image_path)) + File::delete($image_path); + + return redirect()->back(); + } } } diff --git a/app/Http/Controllers/Backend/Students/StudentController.php b/app/Http/Controllers/Backend/Students/StudentController.php index 9ee567e..042a70d 100644 --- a/app/Http/Controllers/Backend/Students/StudentController.php +++ b/app/Http/Controllers/Backend/Students/StudentController.php @@ -9,6 +9,7 @@ use Exception; use Illuminate\Support\Facades\Hash; use File; +use Carbon\Carbon; class StudentController extends Controller { @@ -36,10 +37,6 @@ public function create() public function store(Request $request) { try { - $request->merge([ - 'birthDate' => \Carbon\Carbon::createFromFormat('d F, Y', $request->birthDate)->format('Y-m-d'), - ]); - $student = new Student(); $student->name_en = $request->fullName_en; $student->name_bn = $request->fullName_bn; @@ -83,7 +80,8 @@ public function show(Student $student) public function edit($id) { $role = Role::get(); - $student = Student::findOrFail(encryptor('decrypt', $id)); + $student = Student::findOrFail(encryptor('decrypt', $id)); + return view('backend.student.edit', compact('role', 'student')); } @@ -93,9 +91,6 @@ public function edit($id) public function update(Request $request, $id) { try { - // $request->merge([ - // 'birthDate' => \Carbon\Carbon::createFromFormat('d F, Y', $request->birthDate)->format('Y-m-d'), - // ]); $student = Student::findOrFail(encryptor('decrypt', $id)); $student->name_en = $request->fullName_en; diff --git a/app/Models/Instructor.php b/app/Models/Instructor.php index 2452541..249ebaa 100644 --- a/app/Models/Instructor.php +++ b/app/Models/Instructor.php @@ -8,4 +8,9 @@ class Instructor extends Model { use HasFactory; + + public function role() + { + return $this->belongsTo(Role::class); + } } diff --git a/app/Models/Role.php b/app/Models/Role.php index dfcfdf5..f4c86f8 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -10,10 +10,17 @@ class Role extends Model use HasFactory; // relation with user - public function users(){ + public function users() + { return $this->hasMany(User::class); } - public function students(){ + public function students() + { return $this->hasMany(Student::class); } + + public function instructors() + { + $this->hasMany(Instructor::class); + } } diff --git a/public/uploads/instructors/5411700934236.jpg b/public/uploads/instructors/5411700934236.jpg new file mode 100644 index 0000000..a12b602 Binary files /dev/null and b/public/uploads/instructors/5411700934236.jpg differ diff --git a/public/uploads/instructors/php3653.tmp b/public/uploads/instructors/php3653.tmp new file mode 100644 index 0000000..a12b602 Binary files /dev/null and b/public/uploads/instructors/php3653.tmp differ diff --git a/public/uploads/instructors/phpFB58.tmp b/public/uploads/instructors/phpFB58.tmp new file mode 100644 index 0000000..a12b602 Binary files /dev/null and b/public/uploads/instructors/phpFB58.tmp differ diff --git a/public/uploads/students/5611700924451.png b/public/uploads/students/5611700924451.png new file mode 100644 index 0000000..09c6a9e Binary files /dev/null and b/public/uploads/students/5611700924451.png differ diff --git a/public/uploads/students/9991700926803.jpg b/public/uploads/students/9991700926803.jpg new file mode 100644 index 0000000..876e71f Binary files /dev/null and b/public/uploads/students/9991700926803.jpg differ diff --git a/resources/views/backend/instructor/create.blade.php b/resources/views/backend/instructor/create.blade.php new file mode 100644 index 0000000..c78e98c --- /dev/null +++ b/resources/views/backend/instructor/create.blade.php @@ -0,0 +1,161 @@ +@extends('backend.layouts.app') +@section('title', 'Add Instructor') + +@push('styles') + + + +@endpush + +@section('content') + +
{{$d->role?->name}}
+Instructor Not Found
+