Roman_applicant-site/app/Http/Controllers/admin/FeedbackController.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2024-04-23 14:23:21 +03:00
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\StoreFeedbackRequest;
use App\Http\Requests\admin\UpdateFeedbackRequest;
use App\Models\Feedback;
use App\Models\FeedbackStatus;
class FeedbackController extends Controller
{
public function index()
{
$feedbacks = Feedback::all();
return view('admin.feedback.index', compact('feedbacks'));
}
public function store(StoreFeedbackRequest $request)
{
$validated = $request->validated();
$feedback = new Feedback();
$feedback->contact = $validated['contact'];
$feedback->text = $validated['text'];
$feedback->status_id = $validated['status_id'];
$feedback->save();
return response()->json(["result" => "success"]);
}
public function edit(Feedback $feedback)
{
$feedbackStatuses = FeedbackStatus::pluck('name', 'id');
return view('admin.feedback.edit', compact('feedback', 'feedbackStatuses'));
}
public function update(UpdateFeedbackRequest $request, Feedback $feedback)
{
$validated = $request->validated();
$feedback->contact = $validated['contact'];
$feedback->text = $validated['text'];
$feedback->status_id = $validated['status_id'];
$feedback->save();
return redirect()->route('feedback.index');
}
}