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,119 @@
<?php
namespace Modules\Subscription\app\Http\Controllers;
use Illuminate\Http\Request;
use App\Services\LogoService;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use App\Jobs\SendSubscriptionMailJob;
use Illuminate\Http\RedirectResponse;
use Modules\Setting\app\Models\Setting;
use Modules\Subscription\app\Repositories\SubscriptionRepository;
class SubscriptionController extends Controller
{
protected $subscriptionRepository;
public function __construct()
{
$this->subscriptionRepository = new SubscriptionRepository();
}
/**
* 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') : [];
$subscription = $this->subscriptionRepository->allSubscriptionsEmail($perPage, $filter);
return view('subscription::index', compact('subscription'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('subscription::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(LogoService $logoService, Request $request)
{
$validated = $request->validate([
'email' => 'required|email|unique:subscriptions,email',
]);
try {
$subscription = $this->subscriptionRepository->storeSubscription($validated);
$thumbImage = asset('frontend/images/mail/thumb.png');
dispatch(new SendSubscriptionMailJob(
citizenEmail: $subscription->email,
siteLogo: $logoService->getSiteLogo(),
thumbImage: $thumbImage ?? ''
));
toastr()->success('Thanks for subscribe');
return redirect()->route('home');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back()->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('subscription::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('subscription::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 {
$subscription = $this->subscriptionRepository->deleteSubscriptionEmail($uuid);
if (!$subscription) {
toastr()->error('Subscription email not found.');
return back();
}
toastr()->success('Subscription email deleted successfully.');
return redirect()->route('cms.subscription.index');
} catch (\Throwable $th) {
report($th);
toastr()->error('Something went wrong.');
return back();
}
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\Subscription\app\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CreateSubscriptionRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'email' => 'required|email',
];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
}

View File

View File

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

View File

@@ -0,0 +1,59 @@
<?php
namespace Modules\Subscription\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\Subscription\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('Subscription', '/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('Subscription', '/routes/api.php'));
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace Modules\Subscription\app\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class SubscriptionServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Subscription';
protected string $moduleNameLower = 'subscription';
/**
* 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,68 @@
<?php
namespace Modules\Subscription\app\Repositories;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Modules\Subscription\app\Models\Subscription;
class SubscriptionRepository
{
public function allSubscriptionsEmail($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
{
return Subscription::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 storeSubscription($validated)
{
$result = false;
DB::beginTransaction();
try {
$validated['uuid'] = Str::uuid();
$result = Subscription::create($validated);
if ($result) {
DB::commit();
}
} catch (\Throwable $th) {
report($th);
DB::rollback();
}
return $result;
}
public function findSubscriptionEmailByUuid($uuid)
{
return Subscription::where('uuid', $uuid)->first();
}
public function deleteSubscriptionEmail($uuid)
{
DB::beginTransaction();
try {
$subscription = $this->findSubscriptionEmailByUuid($uuid);
if (!$subscription) {
return null;
}
$subscription->delete();
DB::commit();
return true;
} catch (\Throwable $th) {
DB::rollback();
report($th);
return null;
}
}
}