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,108 @@
<?php
namespace Modules\Consultation\app\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Modules\Consultation\app\Repositories\ConsultationRepository;
use Modules\Consultation\app\Http\Requests\CreateConsultationRequest;
class ConsultationController extends Controller
{
protected $consultationRepository;
public function __construct()
{
$this->consultationRepository = new ConsultationRepository;
}
/**
* 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') : [];
$data['consultations'] = $this->consultationRepository->allConsultationList($perPage, $filter);
$data['consultationCount'] = $data['consultations']->count();
return view('consultation::index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('consultation::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(CreateConsultationRequest $request): RedirectResponse
{
try {
$validated = $request->validated();
$this->consultationRepository->storeConsultationList($validated);
toastr()->success('Consultation created successfully.');
return redirect()->route('doctor_provider');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
/**
* Show the specified resource.
*/
public function show($uuid)
{
$data['consultation'] = $this->consultationRepository->findConsultationListById($uuid);
return view('consultation::show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('consultation::edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($uuid)
{
try {
$consultation = $this->consultationRepository->deleteConsultationList($uuid);
if (!$consultation) {
toastr()->error('Consultation not found.');
return back();
}
toastr()->success('Consultation deleted successfully.');
return redirect()->route('cms.consultation.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Modules\Consultation\app\Http\Requests;
use Modules\Consultation\app\Helpers\Options;
use Illuminate\Foundation\Http\FormRequest;
class CreateConsultationRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'name' => 'required|string|max:200|regex:/^[a-zA-Z. ]+$/',
'email' => 'sometimes|nullable|email|max:255',
'contact_no' => 'required|string|max:20',
'age_group' => 'required|integer|between:1,7',
'procedure_of_interest' => 'required|integer|between:1,5',
'subject' => 'required|string|max:255',
'message' => 'required|string',
'is_aggrement' => 'required|in:10,11',
];
}
public function messages()
{
return [
'name.required' => 'The name field is required.',
'name.string' => 'The name field must be a string.',
'name.max' => 'The name may not be greater than :max characters.',
'name.regex' => 'The name field may only contain letters, spaces, and dots.',
'email.email' => 'The email must be a valid email address.',
'email.max' => 'The email may not be greater than :max characters.',
'contact_no.required' => 'The contact number field is required.',
'contact_no.max' => 'The contact number may not be greater than :max characters.',
'age_group.required' => 'The age group field is required.',
'age_group.integer' => 'The age group must be an integer.',
'age_group.between' => 'The age group must be between :min and :max.',
'procedure_of_interest.required' => 'The procedure of interest field is required.',
'procedure_of_interest.integer' => 'The procedure of interest must be an integer.',
'procedure_of_interest.between' => 'The procedure of interest must be between :min and :max.',
'subject.required' => 'The subject field is required.',
'subject.string' => 'The subject field must be a string.',
'subject.max' => 'The subject may not be greater than :max characters.',
'message.required' => 'The message field is required.',
'is_aggrement.required' => 'The agreement field is required.',
'is_aggrement.in' => 'Invalid value for the agreement field.',
];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
}

View File

View File

@@ -0,0 +1,61 @@
<?php
namespace Modules\Consultation\app\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Consultation\Database\factories\ConsultationFactory;
class Consultation extends Model
{
use HasFactory;
const AGE_GROUP_OPTIONS = [
1 => 'Age 18-24',
2 => 'Age 25-34',
3 => 'Age 35-44',
4 => 'Age 45-54',
5 => 'Age 55 and above',
// 6 => 'Age 65-74',
// 7 => 'Age 75 and Up'
];
const PROCEDURE_OPTIONS = [
1 => 'Hair Transplant',
2 => 'Beard Transplant',
3 => 'Eyebrow Transplant',
4 => 'Platelet Rich Plasma Therapy (PRP)',
5 => 'Growth Factor Concentrate Therapy (GFC)'
];
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'uuid',
'name',
'email',
'contact_no',
'age_group',
'procedure_of_interest',
'subject',
'message',
'is_aggrement',
];
protected static function newFactory(): ConsultationFactory
{
//return ConsultationFactory::new();
}
public function ageGroupOption()
{
return self::AGE_GROUP_OPTIONS[$this->age_group];
}
public function procedureOfInterestOption()
{
return self::PROCEDURE_OPTIONS[$this->procedure_of_interest];
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace Modules\Consultation\app\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class ConsultationServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Consultation';
protected string $moduleNameLower = 'consultation';
/**
* 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\Consultation\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\Consultation\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('Consultation', '/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('Consultation', '/routes/api.php'));
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Modules\Consultation\app\Repositories;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Modules\Consultation\app\Models\Consultation;
class ConsultationRepository
{
public function allConsultationList($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
{
return Consultation::when(array_keys($filter, true), function ($query) use ($filter) {
if (!empty($filter['contact_no'])) {
$query->where('contact_no', $filter['contact_no']);
}
})
->orderBy($sort['by'], $sort['sort'])
->paginate($perPage ?: env('PAGE_LIMIT', 999));
}
public function findConsultationListById($uuid)
{
return Consultation::where('uuid', $uuid)->first();
}
public function storeConsultationList($validated)
{
DB::beginTransaction();
try {
$consultation = new Consultation();
$consultation->uuid = Str::uuid();
$consultation->name = $validated['name'];
$consultation->email = $validated['email'] ?? null;
$consultation->contact_no = $validated['contact_no'];
$consultation->age_group = $validated['age_group'];
$consultation->procedure_of_interest = $validated['procedure_of_interest'];
$consultation->subject = $validated['subject'];
$consultation->message = $validated['message'];
$consultation->is_aggrement = $validated['is_aggrement'] ?? 10;
$consultation->save();
DB::commit();
return $consultation;
} catch (\Throwable $th) {
report($th);
DB::rollback();
return null;
}
}
public function deleteConsultationList($uuid)
{
DB::beginTransaction();
try {
$consultation = $this->findConsultationListById($uuid);
if (!$consultation) {
return null;
}
$consultation->delete();
DB::commit();
return true;
} catch (\Throwable $th) {
DB::rollback();
report($th);
return null;
}
}
}