firstcommit

This commit is contained in:
2025-08-17 16:23:14 +05:45
commit 76bf4c0a18
2648 changed files with 362795 additions and 0 deletions

View File

@@ -0,0 +1,131 @@
<?php
namespace Modules\FAQ\app\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Modules\FAQ\app\Http\Requests\CreateFaqRequest;
use Modules\FAQ\app\Repositories\FaqRepository;
class FAQController extends Controller
{
protected $faqRepository;
public function __construct()
{
$this->faqRepository = new FaqRepository;
}
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
$filter = $request->has('filter') ? $request->input('filter') : [];
$faqs = $this->faqRepository->allfaqs($perPage, $filter);
return view('faq::index', compact('faqs'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('faq::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(CreateFaqRequest $request): RedirectResponse
{
try {
$validated = $request->validated();
$this->faqRepository->storeFaq($validated);
toastr()->success('Faq created successfully!');
return redirect()->route('cms.faqs.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('faq::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($uuid)
{
$faq = $this->faqRepository->findFaqByUuid($uuid);
if (! $faq) {
toastr()->success('Faq not found');
return back();
}
return view('faq::edit', compact('faq'));
}
/**
* Update the specified resource in storage.
*/
public function update(CreateFaqRequest $request, $uuid): RedirectResponse
{
try {
$validated = $request->validated();
$faq = $this->faqRepository->updateFaq($validated, $uuid);
if (! $faq) {
toastr()->success('Faq not found');
return back();
}
return redirect()->route('cms.faqs.index')->with('success', 'Faq updated successfully');
} catch (\Throwable $th) {
report($th);
return redirect()->back()->with('error', 'An error occurred');
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($uuid)
{
DB::beginTransaction();
try {
$faq = $this->faqRepository->deleteFaq($uuid);
if (! $faq) {
toastr()->error('Faq not found');
return back();
}
toastr()->success('FAQ deleted successfully.');
return redirect()->route('cms.faqs.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong');
return back();
}
}
}

View File

View File

View File

@@ -0,0 +1,51 @@
<?php
namespace Modules\FAQ\app\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateFaqRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'question' => 'required|string|max:1000',
'answer' => 'required|string|max:1000',
'ordering' => 'required|integer|min:1',
'status' => 'required|in:active,inactive',
];
}
public function messages()
{
return [
'question.required' => 'The question field is required.',
'question.string' => 'The question field must be a string.',
'question.max' => 'The question may not be greater than 1000 characters.',
'answer.required' => 'The answer field is required.',
'answer.string' => 'The answer field must be a string.',
'answer.max' => 'The answer may not be greater than 1000 characters.',
'ordering.required' => 'The ordering field is required.',
'ordering.integer' => 'The ordering field must be an integer.',
'ordering.min' => 'The ordering field must be at least 1.',
'status.required' => 'The status field is required.',
'status.in' => 'The status field must be either "active" or "inactive".',
];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
// return auth()->user()->can('users.create');
}
}