PATH:
home
/
lab2454c
/
westernclear.net
/
app
/
Http
/
Controllers
/
Admin
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\Faq; use App\Models\FaqCategory; class FaqController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data['faqs'] = Faq::paginate('10'); $data['faqCategories'] = FaqCategory::all(); return view('admin.faq.list', $data); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $data['categories'] = FaqCategory::where('status', 'active')->get(); return view('admin.faq.create', $data); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $values = $request->validate([ "question"=>'required|string|max:255', "answer"=>'required|string|max:1000', "category"=>'required|integer|exists:faq_categories,id', ]); //dd($values); $category = FaqCategory::find($values['category']); $faq = new Faq(); $faq->fill($values); $faq->category()->associate($category); $faq->save(); $notify[] = ['success', 'FAQ is added!']; return redirect()->route('faq.index')->withNotify($notify); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(Faq $faq) { $data['faq'] = $faq; $data['categories'] = FaqCategory::where('status', 'active')->get(); return view('admin.faq.edit', $data); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, Faq $faq) { $changed = false; $values = $request->validate([ "question"=>'required|string|max:255', "answer"=>'required|string|max:1000', "category"=>'required|integer|exists:faq_categories,id', ]); $faq->fill($values); if ($faq->isDirty()) { $faq->save(); $changed = true; } //Check for Category Cahnges $category = FaqCategory::find($values['category']); if ($category != $faq->category) { $faq->category()->associate($category); $faq->save(); $changed = true; } if (! $changed) { $notify[] = ['warning', 'No changes done to save']; return redirect()->route('faq.index')->withNotify($notify); } $notify[] = ['success', 'FAQ is Updated!']; return redirect()->route('faq.index')->withNotify($notify); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Faq $faq) { if (isset($faq)) { $faq->delete(); } $notify[] = ['success', 'Faq is Deleted!']; return redirect()->route('faq.index')->withNotify($notify); } }
[-] HomeBannerController.php
[edit]
[-] PasswordController.php
[edit]
[-] AdvisorController.php
[edit]
[+]
..
[-] SiteSettingController.php
[edit]
[-] PageController.php
[edit]
[-] FormController.php
[edit]
[-] SocialLinkController.php
[edit]
[-] EducationQuestionController.php
[edit]
[-] AdminUserController.php
[edit]
[+]
Home
[-] LeadershipController.php
[edit]
[-] FaqController.php
[edit]
[-] GalleryController.php
[edit]
[-] LoginController.php
[edit]
[-] InvitationCodeController.php
[edit]
[-] FormCategoryController.php
[edit]
[-] DashboardController.php
[edit]
[-] FaqCategoryController.php
[edit]
[-] InsightController.php
[edit]
[-] EducationCategoryController.php
[edit]