-
Notifications
You must be signed in to change notification settings - Fork 2
/
FrequentQuestionController.php
83 lines (69 loc) · 1.94 KB
/
FrequentQuestionController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace App\Http\Controllers\Crew;
use App\Http\Controllers\Controller;
use App\Models\FrequentQuestion;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
class FrequentQuestionController extends Controller
{
/**
* Display a listing of the frequent questions
*
* @return View
*/
public function index()
{
if (Auth::user()->cannot('viewAny', FrequentQuestion::class)) {
abort(403);
}
$faqs = FrequentQuestion::all();
return view('crew.faqs.index', compact('faqs'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
if (Auth::user()->cannot('create', FrequentQuestion::class)) {
abort(403);
}
return view('crew.faqs.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
if (Auth::user()->cannot('create', FrequentQuestion::class)) {
abort(403);
}
$faq = FrequentQuestion::create($request->validate([
'question' => 'required|min:5|max:255|string|unique:frequent_questions,question',
'answer' => 'required|min:5|max:800|string'
]));
return redirect(route('moderator.faqs.show', $faq));
}
/**
* Display the specified resource.
*/
public function show(FrequentQuestion $faq)
{
if (Auth::user()->cannot('view', $faq)) {
abort(403);
}
return view('crew.faqs.show', compact('faq'));
}
/**
* Remove the specified resource from storage.
*/
public function destroy(FrequentQuestion $faq)
{
if (Auth::user()->cannot('delete', $faq)) {
abort(403);
}
$faq->delete();
return redirect(route('moderator.faqs.index'))
->banner('You deleted the FAQ successfully');
}
}