diff --git a/app/Http/Controllers/CcbrtRelationController.php b/app/Http/Controllers/CcbrtRelationController.php index 8c11ba8..8535a8a 100644 --- a/app/Http/Controllers/CcbrtRelationController.php +++ b/app/Http/Controllers/CcbrtRelationController.php @@ -4,7 +4,8 @@ use Illuminate\Http\Request; use App\Models\CcbrtRelation; -use App\Models\User; // Make sure to import the User model +use App\Models\User; +use App\Models\Departments; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; @@ -18,10 +19,12 @@ class CcbrtRelationController extends Controller public function index() { $user = Auth::user(); + $departments = Departments::all(); + $relations = CcbrtRelation::where('userId', $user->id)->get(); // Fetch the authenticated user's data $user = User::find($user->id); - return view('ccbrt_relation.index', compact('user')); + return view('ccbrt_relation.index', compact('user', 'departments', 'relations')); } /** diff --git a/app/Http/Controllers/LanguageKnowledgeController.php b/app/Http/Controllers/LanguageKnowledgeController.php index 8ba0766..f081fc5 100644 --- a/app/Http/Controllers/LanguageKnowledgeController.php +++ b/app/Http/Controllers/LanguageKnowledgeController.php @@ -3,8 +3,146 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Models\User; +use App\Models\LanguageKnowledge; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Validator; class LanguageKnowledgeController extends Controller { - // + /** + * Display a listing of the language knowledge for the authenticated user. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + $user = Auth::user(); + + if (!$user) { + return redirect()->route('login')->with('error', 'Unauthorized access.'); + } + + $languageKnowledge = LanguageKnowledge::where('userId', $user->id)->get(); + + return view('language.index', compact('languageKnowledge', 'user')); + } + + + /** + * Show the form for creating a new language knowledge entry. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + return view('language_knowledge.create'); + } + + /** + * Store a newly created language knowledge in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $validator = Validator::make($request->all(), [ + 'language' => 'required|string|max:255', + 'speaking' => 'required|string|max:255', + 'reading' => 'required|string|max:255', + 'writing' => 'required|string|max:255', + ]); + + if ($validator->fails()) { + return redirect()->back()->withErrors($validator)->withInput(); + } + + LanguageKnowledge::create([ + 'userId' => Auth::id(), + 'language' => $request->input('language'), + 'speaking' => $request->input('speaking'), + 'reading' => $request->input('reading'), + 'writing' => $request->input('writing'), + 'delete_status' => 0, // Assuming delete_status is used for soft deletes + ]); + + return redirect()->route('language_knowledge.index')->with('success', 'Language knowledge added successfully.'); + } + + /** + * Show the form for editing the specified language knowledge. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + $languageKnowledge = LanguageKnowledge::findOrFail($id); + + // Check if the authenticated user owns this language knowledge + if ($languageKnowledge->userId != Auth::id()) { + return redirect()->route('language_knowledge.index')->with('error', 'Unauthorized access.'); + } + + return view('language_knowledge.edit', compact('languageKnowledge')); + } + + /** + * Update the specified language knowledge in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + $validator = Validator::make($request->all(), [ + 'language' => 'required|string|max:255', + 'speaking' => 'required|string|max:255', + 'reading' => 'required|string|max:255', + 'writing' => 'required|string|max:255', + ]); + + if ($validator->fails()) { + return redirect()->back()->withErrors($validator)->withInput(); + } + + $languageKnowledge = LanguageKnowledge::findOrFail($id); + + // Check if the authenticated user owns this language knowledge + if ($languageKnowledge->userId != Auth::id()) { + return redirect()->route('language_knowledge.index')->with('error', 'Unauthorized access.'); + } + + $languageKnowledge->language = $request->input('language'); + $languageKnowledge->speaking = $request->input('speaking'); + $languageKnowledge->reading = $request->input('reading'); + $languageKnowledge->writing = $request->input('writing'); + $languageKnowledge->save(); + + return redirect()->route('language_knowledge.index')->with('success', 'Language knowledge updated successfully.'); + } + + /** + * Remove the specified language knowledge from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + $languageKnowledge = LanguageKnowledge::findOrFail($id); + + // Check if the authenticated user owns this language knowledge + if ($languageKnowledge->userId != Auth::id()) { + return redirect()->route('language_knowledge.index')->with('error', 'Unauthorized access.'); + } + + // Soft delete by setting delete_status to 1 + $languageKnowledge->delete_status = 1; + $languageKnowledge->save(); + + return redirect()->route('language_knowledge.index')->with('success', 'Language knowledge deleted successfully.'); + } } diff --git a/resources/views/ccbrt_relation/index.blade.php b/resources/views/ccbrt_relation/index.blade.php index 6e0206a..9d20463 100644 --- a/resources/views/ccbrt_relation/index.blade.php +++ b/resources/views/ccbrt_relation/index.blade.php @@ -75,56 +75,80 @@ function handleProfilePictureChange(input) {
Names | +Relation | +Department | +Position | +
---|---|---|---|
{{ $relation->names }} | +{{ $relation->relation }} | +{{ $relation->department }} | +{{ $relation->position }} | +
{{ $user->email }}
-{{ $user->department->name }}
-