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') + +