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,130 @@
<?php
namespace Modules\ContactUs\app\Http\Controllers;
use App\Mail\ReplyToMail;
use App\Jobs\ReplyToMailJob;
use Illuminate\Http\Request;
use App\Services\LogoService;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Modules\ContactUs\app\Models\ContactUs;
use Modules\ContactUs\app\Repositories\ContactUsRepository;
use Modules\ContactUs\app\Http\Requests\CreateContactUsRequest;
class ContactUsController extends Controller
{
protected $contactUsRepository;
public function __construct()
{
$this->contactUsRepository = new ContactUsRepository;
}
/**
* 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['contactUsList'] = $this->contactUsRepository->allContactList($perPage, $filter);
$data['contactUsCount'] = $data['contactUsList']->count();
// dd(($data['contactUsCount']));
return view('contactus::index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function replyToMail(LogoService $logoService, Request $request, $uuid)
{
$citizenEmail = ContactUs::where('uuid', $uuid)->first();
if (!$citizenEmail) {
return null;
}
dispatch(new ReplyToMailJob(
$citizenEmail,
$request->content,
$logoService->getSiteLogo()
));
return redirect()->route('cms.contactUs.index');
}
public function create()
{
return view('contactus::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(CreateContactUsRequest $request): RedirectResponse
{
try {
$validated = $request->validated();
$this->contactUsRepository->storeContactUsList($validated);
toastr()->success('Contact detail created successfully.');
return redirect()->route('cms.contactus.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
/**
* Show the specified resource.
*/
public function show($uuid)
{
$data['contactUs'] = $this->contactUsRepository->findContactUsListById($uuid);
return view('contactus::show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('contactus::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 {
$contact_us = $this->contactUsRepository->deleteContactUsList($uuid);
if (!$contact_us) {
toastr()->error('Contact detail not found.');
return back();
}
toastr()->success('Contact detail deleted successfully.');
return redirect()->route('cms.contactus.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Modules\ContactUs\app\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateContactUsRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'full_name' => 'required|string|max:200|regex:/^[a-zA-Z. ]+$/',
'address' => 'sometimes|nullable|string|max:200',
'email' => 'sometimes|nullable|email',
'subject' => 'sometimes|nullable|string|max:1000',
'message' => 'required|string|max:1000',
'phone' => 'sometimes|nullable|numeric|digits:10',
];
}
public function messages()
{
return [
'full_name.required' => 'The full name field is required.',
'full_name.string' => 'The full name must be a string.',
'full_name.max' => 'The full name may not be greater than 200 characters.',
'full_name.regex' => 'The full name may only contain letters, dots, and spaces.',
'address.string' => 'The address must be a string.',
'address.max' => 'The address may not be greater than 200 characters.',
'email.email' => 'Invalid email format.',
'subject.string' => 'The subject must be a string.',
'subject.max' => 'The subject may not be greater than 1000 characters.',
'message.required' => 'The message field is required.',
'message.string' => 'The message must be a string.',
'message.max' => 'The message may not be greater than 1000 characters.',
'phone.numeric' => 'The phone must be a number.',
'phone.digits' => 'The phone must be exactly 10 digits long.'
];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
}

View File

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\ContactUs\app\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\ContactUs\Database\factories\ContactUsFactory;
class ContactUs extends Model
{
// use HasFactory;
use SoftDeletes;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'uuid',
'full_name',
'address',
'email',
'subject',
'message',
'phone',
];
protected static function newFactory(): ContactUsFactory
{
//return ContactUsFactory::new();
}
}

View File

View File

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

View File

@@ -0,0 +1,74 @@
<?php
namespace Modules\ContactUs\app\Repositories;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Modules\ContactUs\app\Models\ContactUs;
class ContactUsRepository
{
public function allContactList($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
{
return ContactUs::when(array_keys($filter, true), function ($query) use ($filter) {
if (!empty($filter['email'])) {
$query->where('email', $filter['email']);
}
})
->orderBy($sort['by'], $sort['sort'])
->paginate($perPage ?: env('PAGE_LIMIT', 999));
}
public function findContactUsListById($uuid)
{
return ContactUs::where('uuid', $uuid)->first();
}
public function storeContactUsList($validated)
{
DB::beginTransaction();
try {
$contact_us = new ContactUs();
$contact_us->uuid = Str::uuid();
$contact_us->full_name = $validated['full_name'];
$contact_us->address = $validated['address'] ?? null;
$contact_us->email = $validated['email'] ?? null;
$contact_us->phone = $validated['phone'];
$contact_us->subject = $validated['subject'] ?? null;
$contact_us->message = $validated['message'];
$contact_us->save();
DB::commit();
return $contact_us;
} catch (\Throwable $th) {
report($th);
DB::rollback();
return null;
}
}
public function deleteContactUsList($uuid)
{
DB::beginTransaction();
try {
$contact_us = $this->findContactUsListById($uuid);
if (!$contact_us) {
return null;
}
$contact_us->delete();
DB::commit();
return true;
} catch (\Throwable $th) {
DB::rollback();
report($th);
return null;
}
}
}