diff --git a/app/Http/Controllers/Admin/Data/FaqController.php b/app/Http/Controllers/Admin/Data/FaqController.php index 819c87cbe4..9a6d5fa510 100644 --- a/app/Http/Controllers/Admin/Data/FaqController.php +++ b/app/Http/Controllers/Admin/Data/FaqController.php @@ -26,14 +26,28 @@ class FaqController extends Controller { */ public function getFaqIndex(Request $request) { $query = Faq::query(); - $data = $request->only(['faq_category_id', 'name']); - if (isset($data['faq_category_id']) && $data['faq_category_id'] != 'none') { - $query->where('faq_category_id', $data['faq_category_id']); + $data = $request->only(['content', 'tags']); + if (isset($data['content'])) { + $content = $data['content']; + $query->where(function ($query) use ($content) { + $query->where('question', 'LIKE', '%'.$content.'%')->orWhere('answer', 'LIKE', '%'.$content.'%'); + }); } - if (isset($data['name'])) { - $query->where('name', 'LIKE', '%'.$data['name'].'%'); + + if (isset($data['tags'])) { + foreach ($data['tags'] as $tag) { + // json decode the tag column + $query->whereJsonContains('tags', $tag); + } } + $tags = Config::get('lorekeeper.faq'); + // tags is an array of names, make it so their key is their name also + $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('admin.faq.faq', [ 'faqs' => $query->paginate(20)->appends($request->query()), 'tags' => Config::get('lorekeeper.faq'), @@ -49,10 +63,13 @@ public function getCreateFaqQuestion() { $tags = Config::get('lorekeeper.faq'); // tags is an array of names, make it so their key is their name also $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('admin.faq.create_edit_question', [ 'faq' => new Faq, 'tags' => $tags, - ]); } @@ -71,6 +88,10 @@ public function getEditFaqQuestion($id) { $tags = Config::get('lorekeeper.faq'); // tags is an array of names, make it so their key is their name also $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('admin.faq.create_edit_question', [ 'faq' => $faq, 'tags' => $tags, @@ -115,7 +136,7 @@ public function postCreateEditFaqQuestion(Request $request, FaqService $service, public function getDeleteFaqQuestion($id) { $faq = Faq::find($id); - return view('admin.faqs._delete_faq', [ + return view('admin.faq._delete_question', [ 'faq' => $faq, ]); } @@ -137,6 +158,6 @@ public function postDeleteFaqQuestion(Request $request, FaqService $service, $id } } - return redirect()->to('admin/data/faqs'); + return redirect()->to('admin/data/faq'); } } diff --git a/app/Http/Controllers/BrowseController.php b/app/Http/Controllers/BrowseController.php index 124eb61a9c..72737b284a 100644 --- a/app/Http/Controllers/BrowseController.php +++ b/app/Http/Controllers/BrowseController.php @@ -645,8 +645,12 @@ public function getFaq(Request $request) { $tags = Config::get('lorekeeper.faq'); // tags is an array of names, make it so their key is their name also $tags = array_combine($tags, $tags); + $tags = array_map(function ($tag) { + return ucwords($tag); + }, $tags); + ksort($tags); return view('browse.faq', [ - 'faqs' => Faq::visible(Auth::check() ? Auth::user() : null)->get(), + 'faqs' => Faq::visible(Auth::check() ? Auth::user() : null)->orderBy('created_at', 'DESC')->get(), 'tags' => $tags, ]); } @@ -673,7 +677,7 @@ public function getFaqSearch(Request $request) { $query->where('question', 'LIKE', '%'.$content.'%')->orWhere('answer', 'LIKE', '%'.$content.'%'); }); } - })->get(), + })->orderBy('created_at', 'DESC')->get(), ]); } } diff --git a/config/lorekeeper/faq.php b/config/lorekeeper/faq.php index 34badf9701..82f55211e9 100644 --- a/config/lorekeeper/faq.php +++ b/config/lorekeeper/faq.php @@ -8,6 +8,11 @@ 'lorekeeper', 'world', 'species', - 'guidelines' + 'guidelines', + 'redesigns', + 'myos', + 'items', + 'prompts', + 'events' ]; diff --git a/resources/views/admin/faq/_delete_question.blade.php b/resources/views/admin/faq/_delete_question.blade.php new file mode 100644 index 0000000000..38ae0cd842 --- /dev/null +++ b/resources/views/admin/faq/_delete_question.blade.php @@ -0,0 +1,20 @@ +@if ($faq) + {!! Form::open(['url' => 'admin/data/faq/delete/' . $faq->id]) !!} + +
+ You are about to delete the question
+
+ {{ $faq->question }}
+
+ This is not reversible.
+
Are you sure you want to delete it?
+ +