Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sheby460/E-docs into chum…
Browse files Browse the repository at this point in the history
…aBranch
  • Loading branch information
sheby460 committed Jul 16, 2024
2 parents df42eb8 + 1e42e07 commit 54e6f88
Show file tree
Hide file tree
Showing 15 changed files with 623 additions and 372 deletions.
7 changes: 5 additions & 2 deletions app/Http/Controllers/CcbrtRelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'));
}

/**
Expand Down
140 changes: 139 additions & 1 deletion app/Http/Controllers/LanguageKnowledgeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}
103 changes: 76 additions & 27 deletions resources/views/ccbrt_relation/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,63 +75,112 @@ function handleProfilePictureChange(input) {
</div>
</div>
<ul class="nav nav-tabs">
<li class="nav-item"><a href="#family" class="nav-link"
data-bs-toggle="tab">CCBRT Relation</a></li>
<li class="nav-item"><a href="{{ route('profile.index') }}"
class="nav-link">User Info</a></li>
<li class="nav-item"><a href="#security" class="nav-link"
data-bs-toggle="tab">Password</a></li>
<li class="nav-item"><a href="{{ route('family-details.index') }}"
class="active nav-link">Family Details</a></li>
<li class="nav-item"><a href="{{ route('health-details.index') }}"
class=" nav-link">Health Details</a></li>
<li class="nav-item"><a href="{{ route('relation-details.index') }}"
class="active nav-link">CCBRT Reation</a></li>
<li class="nav-item"><a href="{{ route('language_knowledge.index') }}"
class="nav-link">Language</a> </li>

<li class="nav-item"><a href="#policies" class="nav-link"
data-bs-toggle="tab">Policies</a></li>
</ul>
<div class="tab-content pt-3">
<div class="tab-pane" id="family">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="tab-pane active" id="family">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
Add CCBRT Relation
</div>

<div class="card-body">

<form method="POST" action="{{ route('relation-details.addRelationData') }}">
<form method="POST"
action="{{ route('relation-details.addRelationData') }}">
@csrf

<div class="row">
<div class="col-12 col-md-6">
<div class="col-12 col-md-3">
<div class="form-group">
<label>Names</label>
<input type="text" class="form-control" name="names" value="{{ old('names') }}">

<input type="text" class="form-control"
name="names"
value="{{ old('names') }}">
</div>

</div>
<div class="col-12 col-md-3">
<div class="form-group">
<label>Relation</label>
<input type="text" class="form-control" name="relation" value="{{ old('relation') }}">

<input type="text" class="form-control"
name="relation"
value="{{ old('relation') }}">
</div>
</div>

<div class="col-12 col-md-6">
<div class="col-12 col-md-3">
<div class="form-group">
<label>Department</label>
<input type="text" class="form-control" name="department" value="{{ old('department') }}">

<select class="form-control"
name="department">
<option value="">Select
Department
</option>
@foreach ($departments as $department)
<option
value="{{ $department->id }}"
{{ old('department') == $department->id ? 'selected' : '' }}>
{{ $department->dept_name }}
</option>
@endforeach
</select>
</div>

</div>
<div class="col-12 col-md-3">
<div class="form-group">
<label>Position</label>
<input type="text" class="form-control" name="position" value="{{ old('position') }}">

<input type="text" class="form-control"
name="position"
value="{{ old('position') }}">
</div>
</div>
</div>

<div class="row">
<div class="col d-flex justify-content-end">
<button type="submit" class="btn btn-primary">Add Relation Data</button>
<button type="submit"
class="btn btn-primary">Add Relation
Data</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<hr>

<h3>Existing Relations</h3>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Names</th>
<th>Relation</th>
<th>Department</th>
<th>Position</th>
</tr>
</thead>
<tbody>
@foreach ($relations as $relation)
<tr>
<td>{{ $relation->names }}</td>
<td>{{ $relation->relation }}</td>
<td>{{ $relation->department }}</td>
<td>{{ $relation->position }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 54e6f88

Please sign in to comment.