diff --git a/app/Http/Controllers/FeedbackController.php b/app/Http/Controllers/FeedbackController.php index 249a4e022..5956160d4 100644 --- a/app/Http/Controllers/FeedbackController.php +++ b/app/Http/Controllers/FeedbackController.php @@ -3,12 +3,12 @@ namespace App\Http\Controllers; use App\Models\Feedback; +use App\Models\Position; +use App\Models\User; use Illuminate\Http\Request; class FeedbackController extends Controller { - - /** * Show the form for creating a new resource. * @@ -16,18 +16,39 @@ class FeedbackController extends Controller */ public function create() { - // + $positions = Position::all(); + $controllers = User::all(); + + return view('feedback.create', compact('positions', 'controllers')); } /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { - // - } + $data = $request->validate([ + 'position' => 'nullable|exists:positions,callsign', + 'controller' => 'nullable|exists:users,id', + 'feedback' => 'required', + ]); + + $position = isset($data['position']) ? Position::where('callsign', $data['position'])->get()->first() : null; + $controller = isset($data['controller']) ? User::find($data['controller']) : null; + $feedback = $data['feedback']; + $submitter = auth()->user(); + + $feedback = Feedback::create([ + 'feedback' => $feedback, + 'submitter_user_id' => $submitter->id, + 'reference_user_id' => isset($controller) ? $controller->id : null, + 'reference_position_id' => isset($position) ? $position->id : null, + ]); + + return redirect()->route('dashboard')->with('success', 'Feedback submitted!'); + + } } diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 5252b9bef..8d54cc025 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -3,13 +3,13 @@ namespace App\Http\Controllers; use App\Models\Area; +use App\Models\Feedback; use App\Models\Group; use App\Models\ManagementReport; use App\Models\Rating; use App\Models\Training; use App\Models\TrainingActivity; use App\Models\User; -use App\Models\Feedback; use Carbon\Carbon; use Carbon\CarbonPeriod; use Illuminate\Database\Eloquent\Builder; @@ -125,12 +125,13 @@ public function mentors() /** * Index received feedback - * + * * @return \Illuminate\View\View */ - - public function feedback(){ + public function feedback() + { $feedback = Feedback::all(); + return view('reports.feedback', compact('feedback')); } diff --git a/app/Models/Feedback.php b/app/Models/Feedback.php index e2cfcab47..06218973c 100644 --- a/app/Models/Feedback.php +++ b/app/Models/Feedback.php @@ -11,16 +11,18 @@ class Feedback extends Model protected $guarded = []; - public function submitter(){ + public function submitter() + { return $this->belongsTo(User::class, 'submitter_user_id'); } - public function referenceUser(){ + public function referenceUser() + { return $this->belongsTo(User::class, 'reference_user_id'); } - public function referencePosition(){ + public function referencePosition() + { return $this->belongsTo(Position::class, 'reference_position_id'); } - } diff --git a/app/Models/User.php b/app/Models/User.php index 7df082a6d..d473cc020 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -128,11 +128,13 @@ public function getNameAttribute() return $this->first_name . ' ' . $this->last_name; } - public function submittedFeedback(){ + public function submittedFeedback() + { return $this->hasMany(Feedback::class, 'submitter_user_id'); } - public function receivedFeedback(){ + public function receivedFeedback() + { return $this->hasMany(Feedback::class, 'reference_user_id'); } diff --git a/database/migrations/2023_10_08_144001_add_feedback.php b/database/migrations/2023_10_08_144001_add_feedback.php index 4e7175b6d..e03643582 100644 --- a/database/migrations/2023_10_08_144001_add_feedback.php +++ b/database/migrations/2023_10_08_144001_add_feedback.php @@ -21,6 +21,10 @@ public function up() $table->unsignedBigInteger('reference_position_id')->nullable(); $table->boolean('forwarded')->default(false); $table->timestamps(); + + $table->foreign('submitter_user_id')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('reference_user_id')->references('id')->on('users')->onUpdate('CASCADE')->onDelete('CASCADE'); + $table->foreign('reference_position_id')->references('id')->on('positions')->onUpdate('CASCADE')->onDelete('SET NULL'); }); Schema::table('settings', function (Blueprint $table) { diff --git a/resources/views/feedback/create.blade.php b/resources/views/feedback/create.blade.php new file mode 100644 index 000000000..c13357d40 --- /dev/null +++ b/resources/views/feedback/create.blade.php @@ -0,0 +1,106 @@ +@extends('layouts.app') + +@section('title', 'Feedback') +@section('content') + +
+
+
+
+
+ Submit Feedback +
+
+
+
+ @csrf + +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+
+ + + + + @foreach($controllers as $controller) + @browser('isFirefox') + + @else + + @endbrowser + @endforeach + + @error('controller') + {{ $errors->first('controller') }} + @enderror +
+
+ + + + + @foreach($positions as $position) + @browser('isFirefox') + + @else + + @endbrowser + @endforeach + + @error('position') + {{ $errors->first('position') }} + @enderror +
+
+ +
+
+ + + @error('feedback') + {{ $errors->first('feedback') }} + @enderror +
+
+ + + +
+
+
+
+
+ +@endsection \ No newline at end of file diff --git a/resources/views/layouts/sidebar.blade.php b/resources/views/layouts/sidebar.blade.php index 024d27c2e..06ae11a0c 100644 --- a/resources/views/layouts/sidebar.blade.php +++ b/resources/views/layouts/sidebar.blade.php @@ -154,6 +154,8 @@ @can('viewAccessReport', \App\Models\ManagementReport::class) Access @endcan + + Feedback diff --git a/resources/views/reports/feedback.blade.php b/resources/views/reports/feedback.blade.php index 699cd8b5b..e2f93a1ae 100644 --- a/resources/views/reports/feedback.blade.php +++ b/resources/views/reports/feedback.blade.php @@ -39,13 +39,23 @@ @foreach($feedback as $f) - {{ $f->submitter_user_id }} - {{ $f->reference_user_id }} + {{ $f->submitter->name }} ({{ $f->submitter_user_id }}) - {{ $f->reference_position_id }} + @isset($f->referenceUser) + {{ $f->referenceUser->name }} ({{ $f->referenceUser->id }}) + @else + N/A + @endisset - {{ $f->feedback }} + @isset($f->referencePosition) + {{ $f->referencePosition->callsign }} + @else + N/A + @endisset + + + {!! nl2br($f->feedback) !!} @endforeach