Ekapp/skolehjem/app/Http/Controllers/FeedbackController.php

140 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use App\Feedbacks;
use Illuminate\Http\Request;
2020-06-24 06:23:15 +00:00
use Illuminate\Http\Response;
2020-08-03 08:08:03 +00:00
use Illuminate\Support\Facades\DB;
2020-06-24 06:23:15 +00:00
class FeedbackController extends Controller
{
2020-06-30 07:21:21 +00:00
public function __construct()
{
$this->middleware([ "auth" ]);
2020-08-06 13:31:38 +00:00
$this->middleware([ "lang" ]);
2020-06-30 07:21:21 +00:00
2020-08-31 07:36:10 +00:00
$this->middleware([ "check.auth:feedback.show" ])->only("show", "index");
2020-06-30 07:21:21 +00:00
$this->middleware([ "check.auth:feedback.create" ])->only("create", "store");
$this->middleware([ "check.auth:feedback.edit" ])->only("edit", "update");
$this->middleware([ "check.auth:feedback.delete" ])->only("delete");
}
/**
* Display a listing of the resource.
*
2020-06-25 09:19:51 +00:00
* @param Request $request
* @return Response
*/
2020-06-25 09:19:51 +00:00
public function index(Request $request)
{
$feedback = Feedbacks::query()->orderBy('created_at', 'desc')->get();
2020-06-25 09:19:51 +00:00
return Response::detect("feedbacks.index", [ "feedback" => $feedback ]);
}
/**
* Show the form for creating a new resource.
*
2020-06-25 09:19:51 +00:00
* @return Response
*/
public function create()
{
2020-07-30 12:52:40 +00:00
return Response::detect("feedbacks.create");
}
/**
* Store a newly created resource in storage.
*
2020-06-25 09:19:51 +00:00
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
2020-06-25 09:19:51 +00:00
$requestBody = $request->validate([
"message" => "required",
"suggestion_form" => "required|max:255"
2020-06-25 09:19:51 +00:00
]);
$feedbacks = new Feedbacks($requestBody);
$feedbacks->save();
2020-06-25 09:19:51 +00:00
return redirect()->route("root.index");
}
/**
* Display the specified resource.
*
* @param int $id
2020-06-25 09:19:51 +00:00
* @return Response
*/
public function show($id)
{
2020-06-25 09:19:51 +00:00
return Response::detect("feedback.show", [ "feedback" => $id]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
2020-06-25 09:19:51 +00:00
* @return Response
*/
public function edit($id)
{
$feedback = Feedbacks::find($id);
2020-06-25 10:40:26 +00:00
return Response::detect("feedbacks.edit", [
"feedback" => $feedback
]);
}
/**
* Update the specified resource in storage.
*
2020-06-25 09:19:51 +00:00
* @param Request $request
* @param int $id
* @return void
*/
public function update(Request $request, $id)
{
2020-06-25 10:40:26 +00:00
$data = $request->validate([
"time" => "required"
]);
$feedback = Feedbacks::find($id);
2020-06-25 10:40:26 +00:00
$feedback->update($data);
$feedback->save();
return Response::detect("feedbacks.edit", [
"feedback" => $feedback
]);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
2020-06-25 09:19:51 +00:00
* @return Response
*/
public function destroy($id)
{
$feedback = Feedbacks::find($id);
2020-06-25 10:40:26 +00:00
$feedback->delete();
return redirect()->route("feedbacks.index");
}
2020-08-03 08:08:03 +00:00
public function storeajax(Request $request) {
$requestBody = $request->validate([
"message" => "required",
"suggestion_form" => "required|max:255"
]);
$feedbacks = new Feedbacks($requestBody);
$feedbacks->save();
}
}