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');
}
}

View File

View File

@@ -0,0 +1,30 @@
<?php
namespace Modules\FAQ\app\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\FAQ\Database\factories\FaqFactory;
class Faq extends Model
{
// use HasFactory;
use SoftDeletes;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'uuid',
'question',
'answer',
'ordering',
'status'
];
// protected static function newFactory(): FaqFactory
// {
// //return FaqFactory::new();
// }
}

View File

View File

@@ -0,0 +1,114 @@
<?php
namespace Modules\FAQ\app\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class FAQServiceProvider extends ServiceProvider
{
protected string $moduleName = 'FAQ';
protected string $moduleNameLower = 'faq';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.config('modules.paths.generator.component-class.path'));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
$paths[] = $path.'/modules/'.$this->moduleNameLower;
}
}
return $paths;
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Modules\FAQ\app\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* The module namespace to assume when generating URLs to actions.
*/
protected string $moduleNamespace = 'Modules\FAQ\app\Http\Controllers';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')
->namespace($this->moduleNamespace)
->group(module_path('FAQ', '/routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::prefix('api')
->middleware('api')
->namespace($this->moduleNamespace)
->group(module_path('FAQ', '/routes/api.php'));
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Modules\FAQ\app\Repositories;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Modules\FAQ\app\Models\Faq;
class FaqRepository
{
//-- Retrieve all Services
public function allfaqs($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
{
return Faq::when(array_keys($filter, true), function ($query) use ($filter) {
if (! empty($filter['question'])) {
$query->where('question', $filter['question']);
}
if (! empty($filter['answer'])) {
$query->where('answer', 'like', '%'.$filter['answer'].'%');
}
})
->orderBy($sort['by'], $sort['sort'])
->paginate($perPage ?: env('PAGE_LIMIT', 999));
}
//-- Find Service by uuid
public function findFaqByUuid($uuid)
{
return Faq::where('uuid', $uuid)->first();
}
public function storeFaq(array $validated)
{
DB::beginTransaction();
try {
$faq = new Faq();
$faq->uuid = Str::uuid();
$faq->question = $validated['question'];
$faq->answer = $validated['answer'];
$faq->ordering = $validated['ordering'];
$faq->status = $validated['status'];
$faq->save();
DB::commit();
return $faq;
} catch (\Throwable $th) {
report($th);
DB::rollback();
return null;
}
}
public function updateFaq($validated, $uuid)
{
DB::beginTransaction();
try {
$faq = $this->findFaqByUuid($uuid);
if (! $faq) {
return null;
}
$faq->question = $validated['question'];
$faq->answer = $validated['answer'];
$faq->ordering = $validated['ordering'];
$faq->ordering = $validated['ordering'];
$faq->status = $validated['status'];
$faq->save();
return $faq;
DB::commit();
} catch (\Throwable $th) {
report($th);
DB::rollBack();
return null;
}
}
//-- Delete Testimonial
public function deleteFaq(string $uuid)
{
DB::beginTransaction();
try {
$faq = $this->findFaqByUuid($uuid);
if (! $faq) {
return null;
}
$faq->delete();
DB::commit();
return $faq;
} catch (\Throwable $th) {
report($th);
DB::rollBack();
return null;
}
}
}