2020-06-09 07:05:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-06-29 10:56:08 +00:00
|
|
|
use App\Feedbacks;
|
2020-06-09 07:05:07 +00:00
|
|
|
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
|
|
|
|
2020-06-09 07:05:07 +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
|
|
|
|
|
|
|
$this->middleware([ "check.auth:feedback.list" ])->only("index");
|
|
|
|
$this->middleware([ "check.auth:feedback.show" ])->only("show");
|
|
|
|
$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");
|
|
|
|
}
|
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-25 09:19:51 +00:00
|
|
|
public function index(Request $request)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-08-03 06:46:38 +00:00
|
|
|
$feedback = Feedbacks::query()->orderBy('created_at', 'desc')->paginate($request->input("limit", 20));
|
2020-06-25 09:19:51 +00:00
|
|
|
|
2020-06-29 10:56:08 +00:00
|
|
|
return Response::detect("feedbacks.index", [ "feedback" => $feedback ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2020-07-30 12:52:40 +00:00
|
|
|
return Response::detect("feedbacks.create");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-06-25 09:19:51 +00:00
|
|
|
$requestBody = $request->validate([
|
2020-06-30 06:35:40 +00:00
|
|
|
"message" => "required",
|
|
|
|
"suggestion_form" => "required|max:255"
|
2020-06-25 09:19:51 +00:00
|
|
|
]);
|
|
|
|
|
2020-06-30 06:35:40 +00:00
|
|
|
$feedbacks = new Feedbacks($requestBody);
|
|
|
|
$feedbacks->save();
|
2020-06-25 09:19:51 +00:00
|
|
|
|
2020-08-03 06:46:38 +00:00
|
|
|
return redirect()->route("root.index");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-06-25 09:19:51 +00:00
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2020-06-25 09:19:51 +00:00
|
|
|
return Response::detect("feedback.show", [ "feedback" => $id]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-06-25 09:19:51 +00:00
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2020-06-29 10:56:08 +00:00
|
|
|
$feedback = Feedbacks::find($id);
|
2020-06-25 10:40:26 +00:00
|
|
|
|
|
|
|
return Response::detect("feedbacks.edit", [
|
|
|
|
"feedback" => $feedback
|
|
|
|
]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2020-06-25 09:19:51 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return void
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
2020-06-25 10:40:26 +00:00
|
|
|
$data = $request->validate([
|
|
|
|
"time" => "required"
|
|
|
|
]);
|
|
|
|
|
2020-06-29 10:56:08 +00:00
|
|
|
$feedback = Feedbacks::find($id);
|
2020-06-25 10:40:26 +00:00
|
|
|
|
|
|
|
$feedback->update($data);
|
|
|
|
|
|
|
|
$feedback->save();
|
|
|
|
|
|
|
|
return Response::detect("feedbacks.edit", [
|
|
|
|
"feedback" => $feedback
|
|
|
|
]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-06-25 09:19:51 +00:00
|
|
|
* @return Response
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2020-06-29 10:56:08 +00:00
|
|
|
$feedback = Feedbacks::find($id);
|
2020-06-25 10:40:26 +00:00
|
|
|
$feedback->delete();
|
|
|
|
|
2020-08-13 07:08:34 +00:00
|
|
|
return redirect()->route("feedbacks.index");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
2020-08-03 08:08:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function search(Request $request){
|
|
|
|
if($request->ajax()){
|
|
|
|
$output = "<tr>".
|
|
|
|
"<th>Feedback Besked</th>".
|
|
|
|
"<th>Ris el. Ros</th>".
|
2020-08-17 06:26:01 +00:00
|
|
|
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
|
|
|
|
"</tr>";
|
2020-08-03 08:08:03 +00:00
|
|
|
|
|
|
|
//$value = Feedbacks::query('feedbacks')->select('suggestion_form ')->dump();
|
|
|
|
//$value = DB::table('feedbacks')->select('suggestion_form ')->dump();
|
|
|
|
if($request->option === "Ris" || $request->option === "Ros")
|
2020-08-03 08:46:48 +00:00
|
|
|
$feedbacks = Feedbacks::query()->orderBy('created_at', 'desc')->where('suggestion_form', '=', $request->option)
|
2020-08-03 08:08:03 +00:00
|
|
|
->get();
|
|
|
|
else
|
|
|
|
$feedbacks = Feedbacks::all();
|
|
|
|
|
|
|
|
if(count($feedbacks) !== 0){
|
|
|
|
foreach ($feedbacks as $key => $feedback){
|
|
|
|
$output.='<tr>'.
|
|
|
|
'<td>' . $feedback->message . '</td>'.
|
|
|
|
'<td>' . $feedback->suggestion_form . '</td>'.
|
2020-08-17 06:26:01 +00:00
|
|
|
'<td><form method="post" action="' .route("feedbacks.destroy", [ "feedback" => $feedback ]). '" class="w-100 nostyle">'.
|
|
|
|
csrf_field().
|
|
|
|
method_field("delete").
|
|
|
|
|
|
|
|
'<button class="w-100 nostyle" onclick="return confirm(\'Are you sure you want to delete?\');" type="submit"><img class="w-100 cursor-pointer" src="'. asset('/images/icons/trashcan-dark.svg') . '" alt="Delete"></button>'.
|
|
|
|
'</form>'.
|
|
|
|
'</td>'.
|
2020-08-03 08:08:03 +00:00
|
|
|
'</tr>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response($output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|