This commit is contained in:
2025-10-22 20:08:22 +05:00
commit 736e3bef18
2573 changed files with 120385 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders;
use App\Filament\Clusters\Loans\LoanOrders\Pages\CreateLoanOrder;
use App\Filament\Clusters\Loans\LoanOrders\Pages\EditLoanOrder;
use App\Filament\Clusters\Loans\LoanOrders\Pages\ListLoanOrders;
use App\Filament\Clusters\Loans\LoanOrders\Pages\ViewLoanOrder;
use App\Filament\Clusters\Loans\LoanOrders\Schemas\LoanOrderForm;
use App\Filament\Clusters\Loans\LoanOrders\Schemas\LoanOrderInfolist;
use App\Filament\Clusters\Loans\LoanOrders\Tables\LoanOrdersTable;
use App\Filament\Clusters\Loans\LoansCluster;
use App\Modules\LoanOrder\Models\LoanOrder;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class LoanOrderResource extends Resource
{
protected static ?int $navigationSort = 2;
protected static ?string $model = LoanOrder::class;
protected static ?string $cluster = LoansCluster::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentPlus;
protected static string|BackedEnum|null $activeNavigationIcon = Heroicon::DocumentPlus;
protected static ?string $recordTitleAttribute = 'unique_id';
public static function getNavigationLabel(): string
{
return __('New loan order');
}
public static function getModelLabel(): string
{
return __('module.loan-order::loan-order.loan_order');
}
public static function getPluralModelLabel(): string
{
return __('module.loan-order::loan-order.loan_orders');
}
public static function form(Schema $schema): Schema
{
return LoanOrderForm::configure($schema);
}
public static function infolist(Schema $schema): Schema
{
return LoanOrderInfolist::configure($schema);
}
public static function table(Table $table): Table
{
return LoanOrdersTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListLoanOrders::route('/'),
'create' => CreateLoanOrder::route('/create'),
'view' => ViewLoanOrder::route('/{record}'),
'edit' => EditLoanOrder::route('/{record}/edit'),
];
}
/**
* @return Builder<LoanOrder>
*/
public static function getRecordRouteBindingEloquentQuery(): Builder
{
return parent::getRecordRouteBindingEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders\Pages;
use App\Filament\Clusters\Loans\LoanOrders\LoanOrderResource;
use Filament\Resources\Pages\CreateRecord;
class CreateLoanOrder extends CreateRecord
{
protected static string $resource = LoanOrderResource::class;
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders\Pages;
use App\Filament\Clusters\Loans\LoanOrders\LoanOrderResource;
use Filament\Actions\DeleteAction;
use Filament\Actions\ForceDeleteAction;
use Filament\Actions\RestoreAction;
use Filament\Actions\ViewAction;
use Filament\Resources\Pages\EditRecord;
class EditLoanOrder extends EditRecord
{
protected static string $resource = LoanOrderResource::class;
protected function getHeaderActions(): array
{
return [
ViewAction::make(),
DeleteAction::make(),
ForceDeleteAction::make(),
RestoreAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders\Pages;
use App\Filament\Clusters\Loans\LoanOrders\LoanOrderResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListLoanOrders extends ListRecords
{
protected static string $resource = LoanOrderResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders\Pages;
use App\Filament\Clusters\Loans\LoanOrders\LoanOrderResource;
use Filament\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;
class ViewLoanOrder extends ViewRecord
{
protected static string $resource = LoanOrderResource::class;
protected function getHeaderActions(): array
{
return [
EditAction::make(),
];
}
}

View File

@@ -0,0 +1,333 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders\Schemas;
use App\Modules\LoanOrder\Models\LoanOrderRequiredDocs;
use App\Modules\LoanOrder\Repositories\LoanOrderRepository;
use App\Modules\OrderStatus\Repositories\OrderStatusRepository;
use App\Modules\PersonStates\Repositories\EducationRepository;
use App\Modules\PersonStates\Repositories\MarriageRepository;
use App\Modules\PhoneNumberVerification\Rules\PhoneNumberVerificationRule;
use App\Modules\Region\Repositories\RegionRepository;
use App\Modules\TurkmenPassport\Repositories\TurkmenPassportRepository;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Fieldset;
use Filament\Schemas\Components\FusedGroup;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Wizard;
use Filament\Schemas\Components\Wizard\Step;
use Filament\Schemas\Schema;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
class LoanOrderForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->columns(4)
->components([
Hidden::make('source')->default('web'),
Hidden::make('user_id')->default(Auth::id()),
Section::make(__('New loan order'))
->columnSpan(4)
->columns(4)
->components([
Select::make('status')
->label(__('Status'))
->options(OrderStatusRepository::statusValues())
->default(OrderStatusRepository::defaultStatus())
->native(false)
->required()
->columnSpan(2),
Select::make('satisfiable')
->label(__('Loan history'))
->options(LoanOrderRepository::satisfiableValues())
->native(false)
->columnSpan(2),
Select::make('loan_order_required_doc_id')
->label(__('Required documents'))
->relationship('requiredDocs', 'name')
->searchable()
->native(false)
->preload()
->live()
->afterStateUpdated(function ($state, callable $set) {
if ($state) {
/** @var null|LoanOrderRequiredDocs */
$requiredDoc = LoanOrderRequiredDocs::find($state);
if ($requiredDoc) {
$set('notes', $requiredDoc->value);
}
}
})
->columnSpanFull(),
RichEditor::make('notes')
->label(__('Bellik'))
->columnSpanFull(),
]),
Wizard::make([
Step::make(__('Loan & Bank'))
->schema([
Fieldset::make(__('Loan type and amount'))
->schema([
Select::make('loan_type')
->label(__('Loan type'))
->relationship('loanType', 'name')
->required(),
TextInput::make('loan_amount')
->label(__('Loan amount'))
->numeric()
->required()
->minValue(1)
->maxValue(40000)
->suffix('TMT')
->belowContent(__('Max is 40 000 TMT')),
]),
Fieldset::make(__('Location'))
->schema([
Select::make('region')
->label(__('Region'))
->options(RegionRepository::values())
->live()
->afterStateUpdated(fn (callable $set) => $set('branch_id', null))
->required(),
Select::make('branch_id')
->label(__('Branch'))
->relationship('branch', 'name', function ($query, callable $get) {
$region = $get('region');
if ($region) {
$query->where('region', $region);
}
})
->required(),
]),
]),
Step::make(__('Personal information'))
->columns(8)
->schema([
TextInput::make('customer_name')
->label(__('Name'))
->columnSpan(2)
->required()
->maxLength(255)
->autocomplete(Str::random(10)),
TextInput::make('customer_surname')
->label(__('Surname'))
->columnSpan(2)
->required()
->maxLength(255),
TextInput::make('customer_patronic_name')
->label(__('Patronic name'))
->columnSpan(2)
->maxLength(255),
DatePicker::make('born_at')
->displayFormat('d.m.Y')
->label(__('Birth date'))
->native(false)
->columnSpan(2)
->required()
->beforeOrEqual('today'),
FusedGroup::make([
Select::make('passport_serie')
->label(__('Passport serie'))
->options(TurkmenPassportRepository::values())
->native(false)
->required()
->columnSpan(1),
TextInput::make('passport_id')
->label(__('Passport number'))
->required()
->columnSpan(1)
->mask('999999'),
])
->columnSpan(3)
->label(__('Passport serie and number'))
->columns(2),
DatePicker::make('passport_given_at')
->label(__('Passport given date'))
->columnSpan(2)
->displayFormat('d.m.Y')
->native(false)
->closeOnDateSelection()
->beforeOrEqual('today')
->required(),
TextInput::make('born_place')
->columnSpan(3)
->label(__('Born place (passport)'))
->maxLength(255)
->required(),
TextInput::make('passport_given_by')
->label(__('Passport given by'))
->columnSpan(4)
->maxLength(255)
->required(),
TextInput::make('passport_address')
->columnSpan(4)
->label(__('Proscription for home'))
->maxLength(255)
->required(),
TextInput::make('real_address')
->label(__('Current home address'))
->columnSpan(4)
->maxLength(255)
->required(),
TextInput::make('email')
->label(__('Email'))
->email()
->maxLength(255)
->columnSpan(2),
TextInput::make('phone')
->label(__('Phone'))
->required()
->mask('99 99 99 99')
->prefix('+993')
->rules([
new PhoneNumberVerificationRule,
])
->columnSpan(2),
TextInput::make('phone_additional')
->label(__('Additional phone'))
->mask('99 99 99 99')
->prefix('+993')
->rules([
new PhoneNumberVerificationRule,
])
->columnSpan(2),
TextInput::make('phone_home')
->label(__('Home phone'))
->numeric()
->prefix('+993')
->columnSpan(2),
Select::make('education')
->columnSpan(2)
->label(__('Education'))
->options(EducationRepository::values())
->native(false)
->required(),
Select::make('marriage_status')
->columnSpan(2)
->label(__('Marital status'))
->options(MarriageRepository::values())
->native(false)
->required(),
]),
Step::make(__('Pasport files'))
->columns(4)
->schema([
FileUpload::make('passport_one')
->label(__('Passport (page 1)'))
->image()
->maxSize(4096)
->required()
->columnSpan(2),
FileUpload::make('passport_two')
->label(__('Passport (page 2-3)'))
->image()
->maxSize(4096)
->required()
->columnSpan(2),
FileUpload::make('passport_three')
->label(__('Passport (page 8-9)'))
->image()
->maxSize(4096)
->required()
->columnSpan(2),
FileUpload::make('passport_four')
->label(__('Passport (page 32)'))
->image()
->maxSize(4096)
->required()
->columnSpan(2),
])->columnSpan(4),
Step::make(__('Work'))
->columns(4)
->schema([
Select::make('work_region')
->label(__('Work region'))
->options(RegionRepository::values())
->columnSpan(1)
->live()
->afterStateUpdated(fn (callable $set) => $set('branch_id', null))
->required(),
Select::make('work_province_id')
->label(__('Work province'))
->relationship('workProvince', 'name', function ($query, callable $get) {
$region = $get('work_region');
if ($region) {
$query->where('region', $region);
}
})
->columnSpan(1)
->required(),
TextInput::make('work_company')
->label(__('Work company name'))
->maxLength(255)
->required()
->columnSpan(2),
TextInput::make('work_company_accountant_number')
->label(__('HR number'))
->prefix('+993')
->numeric()
->required()
->columnSpan(1),
TextInput::make('work_position')
->label(__('Work position'))
->required()
->maxLength(255)
->columnSpan(1),
TextInput::make('work_salary')
->label(__('Salary'))
->numeric()
->required()
->columnSpan(1),
DatePicker::make('work_started_at')
->label(__('Work started at'))
->displayFormat('d.m.Y')
->beforeOrEqual('today')
->required()
->columnSpan(1),
]),
])->columnSpan(4),
]);
}
}

View File

@@ -0,0 +1,154 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders\Schemas;
use App\Modules\LoanOrder\Models\LoanOrder;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Schema;
class LoanOrderInfolist
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
TextEntry::make('unique_id')
->placeholder('-'),
TextEntry::make('source')
->placeholder('-'),
TextEntry::make('user.name')
->label('User')
->placeholder('-'),
TextEntry::make('loan_type')
->numeric(),
TextEntry::make('region'),
TextEntry::make('branch.name')
->label('Branch'),
TextEntry::make('customer_name'),
TextEntry::make('customer_surname'),
TextEntry::make('customer_patronic_name')
->placeholder('-'),
TextEntry::make('passport_address'),
TextEntry::make('real_address'),
TextEntry::make('passport_serie'),
TextEntry::make('passport_id'),
TextEntry::make('passport_given_at')
->date(),
TextEntry::make('passport_given_by'),
TextEntry::make('born_place'),
TextEntry::make('born_at')
->date(),
TextEntry::make('email')
->label('Email address')
->placeholder('-'),
TextEntry::make('phone'),
TextEntry::make('phone_additional')
->placeholder('-'),
TextEntry::make('phone_home')
->placeholder('-'),
TextEntry::make('work_region')
->placeholder('-'),
TextEntry::make('workProvince.name')
->label('Work province')
->placeholder('-'),
TextEntry::make('work_company')
->placeholder('-'),
TextEntry::make('work_company_accountant_number')
->placeholder('-'),
TextEntry::make('work_started_at')
->date()
->placeholder('-'),
TextEntry::make('work_salary')
->placeholder('-'),
TextEntry::make('work_position')
->placeholder('-'),
TextEntry::make('education'),
TextEntry::make('marriage_status'),
TextEntry::make('passport_one')
->columnSpanFull(),
TextEntry::make('passport_two')
->columnSpanFull(),
TextEntry::make('passport_three')
->columnSpanFull(),
TextEntry::make('passport_four')
->columnSpanFull(),
TextEntry::make('loan_amount')
->placeholder('-'),
TextEntry::make('card_number')
->placeholder('-'),
TextEntry::make('card_name')
->placeholder('-'),
TextEntry::make('card_month')
->placeholder('-'),
TextEntry::make('card_year')
->placeholder('-'),
TextEntry::make('guarantor_name')
->placeholder('-'),
TextEntry::make('guarantor_surname')
->placeholder('-'),
TextEntry::make('guarantor_patronic_name')
->placeholder('-'),
TextEntry::make('guarantor_passport_serie')
->placeholder('-'),
TextEntry::make('guarantor_passport_id')
->placeholder('-'),
TextEntry::make('guarantor_card_number')
->placeholder('-'),
TextEntry::make('guarantor_card_name')
->placeholder('-'),
TextEntry::make('guarantor_card_month')
->placeholder('-'),
TextEntry::make('guarantor_card_year')
->placeholder('-'),
TextEntry::make('guarantor_note')
->placeholder('-'),
TextEntry::make('guarantor_2_name')
->placeholder('-'),
TextEntry::make('guarantor_2_surname')
->placeholder('-'),
TextEntry::make('guarantor_2_patronic_name')
->placeholder('-'),
TextEntry::make('guarantor_2_passport_serie')
->placeholder('-'),
TextEntry::make('guarantor_2_passport_id')
->placeholder('-'),
TextEntry::make('guarantor_2_card_number')
->placeholder('-'),
TextEntry::make('guarantor_2_card_name')
->placeholder('-'),
TextEntry::make('guarantor_2_card_month')
->placeholder('-'),
TextEntry::make('guarantor_2_card_year')
->placeholder('-'),
TextEntry::make('guarantor_2_note')
->placeholder('-'),
TextEntry::make('loan_card_number')
->placeholder('-'),
TextEntry::make('loan_card_name')
->placeholder('-'),
TextEntry::make('loan_card_month')
->placeholder('-'),
TextEntry::make('loan_card_year')
->placeholder('-'),
TextEntry::make('loan_order_required_doc_id')
->numeric()
->placeholder('-'),
TextEntry::make('status')
->placeholder('-'),
TextEntry::make('satisfiable')
->placeholder('-'),
TextEntry::make('notes')
->placeholder('-')
->columnSpanFull(),
TextEntry::make('created_at')
->dateTime()
->placeholder('-'),
TextEntry::make('updated_at')
->dateTime()
->placeholder('-'),
TextEntry::make('deleted_at')
->dateTime()
->visible(fn (LoanOrder $record): bool => $record->trashed()),
]);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace App\Filament\Clusters\Loans\LoanOrders\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;
class LoanOrdersTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label('ID')
->sortable(),
TextColumn::make('loanType.name')
->label('Тип кредита')
->sortable()
->searchable(),
TextColumn::make('region')
->label('Регион')
->sortable()
->searchable(),
TextColumn::make('branch.name')
->label('Филиал')
->sortable()
->searchable(),
TextColumn::make('customer_name')
->label('Имя клиента')
->sortable()
->searchable(),
TextColumn::make('customer_surname')
->label('Фамилия клиента')
->sortable()
->searchable(),
TextColumn::make('phone')
->label('Телефон')
->searchable(),
TextColumn::make('status')
->label('Статус')
->sortable()
->searchable(),
TextColumn::make('created_at')
->label('Дата создания')
->dateTime()
->sortable()
->toggleable(),
TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
TrashedFilter::make(),
])
->recordActions([
ViewAction::make(),
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
ForceDeleteBulkAction::make(),
RestoreBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace App\Filament\Clusters\Loans\Loans;
use App\Filament\Clusters\Loans\Loans\Pages\ListLoans;
use App\Filament\Clusters\Loans\Loans\Schemas\LoanForm;
use App\Filament\Clusters\Loans\Loans\Tables\LoansTable;
use App\Filament\Clusters\Loans\LoansCluster;
use App\Modules\Loan\Models\Loan;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
class LoanResource extends Resource
{
protected static ?int $navigationSort = 1;
protected static ?string $model = Loan::class;
protected static ?string $cluster = LoansCluster::class;
public static function getNavigationIcon(): string|BackedEnum|Htmlable|null
{
return Heroicon::OutlinedBanknotes;
}
public static function getNavigationLabel(): string
{
return __('My loans');
}
public static function getModelLabel(): string
{
return __('Karz');
}
public static function getPluralModelLabel(): string
{
return __('Karzlar');
}
public static function form(Schema $schema): Schema
{
return LoanForm::configure($schema);
}
public static function table(Table $table): Table
{
return LoansTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListLoans::route('/'),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\Loans\Loans\Pages;
use App\Filament\Clusters\Loans\Loans\LoanResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListLoans extends ListRecords
{
protected static string $resource = LoanResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Filament\Clusters\Loans\Loans\Schemas;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
class LoanForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Hidden::make('user_id')
->default(user()->id),
Hidden::make('passport_serie')
->default(user()->getOption('passport_serie')),
Hidden::make('passport_id')
->default(user()->getOption('passport_id')),
TextInput::make('account_number')
->required()
->string()
->maxLength(23),
]);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Filament\Clusters\Loans\Loans\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class LoansTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('account_number')
->searchable()
->sortable(),
TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Filament\Clusters\Loans;
use BackedEnum;
use Filament\Clusters\Cluster;
use Filament\Pages\Enums\SubNavigationPosition;
use Filament\Support\Icons\Heroicon;
class LoansCluster extends Cluster
{
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBanknotes;
// protected static string|BackedEnum|null $activeNavigationIcon = Heroicon::Banknotes;
protected static ?SubNavigationPosition $subNavigationPosition = SubNavigationPosition::Top;
public static function getNavigationLabel(): string
{
return __('module.loan-order::loan-order.loans');
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Filament\Clusters\Settings\Branches;
use App\Filament\Clusters\Settings\Branches\Pages\ManageBranches;
use App\Filament\Clusters\Settings\Branches\Schemas\BranchForm;
use App\Filament\Clusters\Settings\Branches\Tables\BranchesTable;
use App\Filament\Clusters\Settings\SettingsCluster;
use App\Modules\Branch\Models\Branch;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
class BranchResource extends Resource
{
protected static ?string $model = Branch::class;
protected static ?string $cluster = SettingsCluster::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBuildingOffice2;
protected static ?string $recordTitleAttribute = 'name';
public static function getNavigationGroup(): ?string
{
return __('Branches and provinces');
}
public static function getModelLabel(): string
{
return __('module.branch::base.branch');
}
public static function getPluralModelLabel(): string
{
return __('module.branch::base.branches');
}
public static function form(Schema $schema): Schema
{
return BranchForm::configure($schema);
}
public static function table(Table $table): Table
{
return BranchesTable::configure($table);
}
public static function getPages(): array
{
return [
'index' => ManageBranches::route('/'),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\Settings\Branches\Pages;
use App\Filament\Clusters\Settings\Branches\BranchResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ManageRecords;
class ManageBranches extends ManageRecords
{
protected static string $resource = BranchResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,134 @@
<?php
namespace App\Filament\Clusters\Settings\Branches\Schemas;
use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs;
use App\Modules\Province\Models\Province;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class BranchForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make(__('General Information'))
->columns(2)
->schema([
TextInput::make('unique_code')
->label(__('Unique code'))
->maxLength(255)
->unique(ignoreRecord: true)
->required(),
Select::make('region')
->label(__('Region'))
->options(fn () => regions())
->required()
->native(false)
->searchable()
->live()
->afterStateUpdated(fn ($state, callable $set) => $set('province_id', null)),
Select::make('province_id')
->label(__('Province'))
->relationship('province', 'name')
->options(function (callable $get) {
$region = $get('region');
if (! $region) {
return [];
}
return Province::query()
->where('region', $region)
->where('active', true)
->pluck('name', 'id')
->toArray();
})
->searchable()
->native(false)
->disabled(fn (callable $get): bool => ! $get('region'))
->columnSpanFull(),
Toggle::make('active')
->label(__('Active'))
->default(true)
->required(),
Repeater::make('phone_numbers')
->label(__('Phone numbers'))
->simple(
TextInput::make('phone')
->label(__('Phone Number'))
->prefix('+993')
->numeric()
)
->addActionLabel(__('Add phone number'))
->defaultItems(0)
->columnSpanFull(),
]),
TranslatableTabs::make()
->schema([
TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255),
Textarea::make('address')
->label(__('Address'))
->rows(3),
]),
Section::make(__('Billing Credentials'))
->collapsed()
->collapsible()
->columns(2)
->columnSpanFull()
->schema([
TextInput::make('billing_username')
->label(__('Billing Username'))
->maxLength(255),
TextInput::make('billing_password')
->label(__('Billing Password'))
->password()
->maxLength(255),
TextInput::make('billing_swift_username')
->label(__('Billing SWIFT Username'))
->maxLength(255),
TextInput::make('billing_swift_password')
->label(__('Billing SWIFT Password'))
->password()
->maxLength(255),
TextInput::make('billing_visa_master_username')
->label(__('Billing Visa/Master Username'))
->maxLength(255),
TextInput::make('billing_visa_master_password')
->label(__('Billing Visa/Master Password'))
->password()
->maxLength(255),
TextInput::make('billing_sber_username')
->label(__('Billing Sber Username'))
->maxLength(255),
TextInput::make('billing_sber_password')
->label(__('Billing Sber Password'))
->password()
->maxLength(255),
]),
]);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace App\Filament\Clusters\Settings\Branches\Tables;
use App\Modules\Region\Repositories\RegionRepository;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
class BranchesTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('unique_code')
->label(__('Unique code'))
->searchable()
->sortable(),
TextColumn::make('name')
->label(__('Name'))
->searchable()
->sortable(),
TextColumn::make('region')
->label(__('Region'))
->formatStateUsing(fn (string $state): string => RegionRepository::label($state))
->searchable()
->sortable(),
TextColumn::make('province.name')
->label(__('Province'))
->searchable()
->sortable()
->toggleable(),
IconColumn::make('active')
->label(__('Active'))
->boolean()
->sortable(),
TextColumn::make('created_at')
->label(__('Created At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->label(__('Updated At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
SelectFilter::make('region')
->label(__('Region'))
->options(fn () => regions())
->native(false),
TernaryFilter::make('active')
->label(__('Active'))
->boolean()
->trueLabel(__('Active only'))
->falseLabel(__('Inactive only'))
->native(false),
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Filament\Clusters\Settings\LoanOrderRequiredDocs;
use App\Filament\Clusters\Settings\LoanOrderRequiredDocs\Pages\ManageLoanOrderRequiredDocs;
use App\Filament\Clusters\Settings\LoanOrderRequiredDocs\Schemas\LoanOrderRequiredDocsForm;
use App\Filament\Clusters\Settings\LoanOrderRequiredDocs\Tables\LoanOrderRequiredDocsTable;
use App\Filament\Clusters\Settings\SettingsCluster;
use App\Modules\LoanOrder\Models\LoanOrderRequiredDocs;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
class LoanOrderRequiredDocsResource extends Resource
{
protected static ?string $model = LoanOrderRequiredDocs::class;
protected static ?string $cluster = SettingsCluster::class;
protected static ?int $navigationSort = 2;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedClipboardDocumentList;
protected static ?string $recordTitleAttribute = 'name';
public static function getNavigationGroup(): ?string
{
return __('module.loan-order::loan-order.loans');
}
public static function getModelLabel(): string
{
return __('module.loan-order::loan-order.loan_order_required_docs');
}
public static function getPluralModelLabel(): string
{
return __('module.loan-order::loan-order.loan_order_required_docs');
}
public static function form(Schema $schema): Schema
{
return LoanOrderRequiredDocsForm::configure($schema);
}
public static function table(Table $table): Table
{
return LoanOrderRequiredDocsTable::configure($table);
}
public static function getPages(): array
{
return [
'index' => ManageLoanOrderRequiredDocs::route('/'),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\Settings\LoanOrderRequiredDocs\Pages;
use App\Filament\Clusters\Settings\LoanOrderRequiredDocs\LoanOrderRequiredDocsResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ManageRecords;
class ManageLoanOrderRequiredDocs extends ManageRecords
{
protected static string $resource = LoanOrderRequiredDocsResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Filament\Clusters\Settings\LoanOrderRequiredDocs\Schemas;
use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
class LoanOrderRequiredDocsForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
TranslatableTabs::make('anyLabel')
->columnSpanFull()
->schema([
TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255),
RichEditor::make('value')
->label(__('Value'))
->required()
->maxLength(255),
]),
]);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Filament\Clusters\Settings\LoanOrderRequiredDocs\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class LoanOrderRequiredDocsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label(__('Name'))
->searchable()
->sortable(),
TextColumn::make('created_at')
->label(__('Created At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->label(__('Updated At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Filament\Clusters\Settings\LoanTypes;
use App\Filament\Clusters\Settings\LoanTypes\Pages\ListLoanTypes;
use App\Filament\Clusters\Settings\LoanTypes\Schemas\LoanTypeForm;
use App\Filament\Clusters\Settings\LoanTypes\Schemas\LoanTypeInfolist;
use App\Filament\Clusters\Settings\LoanTypes\Tables\LoanTypesTable;
use App\Filament\Clusters\Settings\SettingsCluster;
use App\Modules\LoanOrder\Models\LoanType;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
class LoanTypeResource extends Resource
{
protected static ?string $model = LoanType::class;
protected static ?string $cluster = SettingsCluster::class;
protected static ?int $navigationSort = 1;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBanknotes;
protected static ?string $recordTitleAttribute = 'name';
public static function getNavigationGroup(): ?string
{
return __('module.loan-order::loan-order.loans');
}
public static function getModelLabel(): string
{
return __('module.loan-order::loan-type.loan_type');
}
public static function getPluralModelLabel(): string
{
return __('module.loan-order::loan-type.loan_type');
}
public static function form(Schema $schema): Schema
{
return LoanTypeForm::configure($schema);
}
public static function infolist(Schema $schema): Schema
{
return LoanTypeInfolist::configure($schema);
}
public static function table(Table $table): Table
{
return LoanTypesTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListLoanTypes::route('/'),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\Settings\LoanTypes\Pages;
use App\Filament\Clusters\Settings\LoanTypes\LoanTypeResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListLoanTypes extends ListRecords
{
protected static string $resource = LoanTypeResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Filament\Clusters\Settings\LoanTypes\Schemas;
use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class LoanTypeForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
TranslatableTabs::make()
->schema([
TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255),
Textarea::make('notes')
->label(__('Notes'))
->rows(3),
]),
Section::make()
->columns(2)
->schema([
TextInput::make('tax')
->label(__('Tax'))
->numeric()
->suffix('%')
->maxLength(255),
TextInput::make('maturity')
->label(__('Loan term'))
->maxLength(255),
Toggle::make('active')
->label(__('Active'))
->default(true)
->required(),
]),
]);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Filament\Clusters\Settings\LoanTypes\Schemas;
use Filament\Infolists\Components\IconEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class LoanTypeInfolist
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make(__('Loan Type Information'))
->columns(2)
->components([
TextEntry::make('name')
->label(__('Name')),
TextEntry::make('tax')
->label(__('Tax'))
->suffix('%')
->default('—'),
TextEntry::make('maturity')
->label(__('Loan term'))
->default('—'),
IconEntry::make('active')
->label(__('Active'))
->boolean(),
TextEntry::make('notes')
->label(__('Notes'))
->columnSpanFull()
->default('—'),
TextEntry::make('created_at')
->label(__('Created At'))
->dateTime(),
TextEntry::make('updated_at')
->label(__('Updated At'))
->dateTime(),
]),
]);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Filament\Clusters\Settings\LoanTypes\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
class LoanTypesTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label(__('Name'))
->searchable()
->sortable(),
TextColumn::make('tax')
->label(__('Tax'))
->suffix('%')
->sortable()
->default('—'),
TextColumn::make('maturity')
->label(__('Loan term'))
->sortable()
->default('—'),
IconColumn::make('active')
->label(__('Active'))
->boolean()
->sortable(),
TextColumn::make('created_at')
->label(__('Created At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->label(__('Updated At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
TernaryFilter::make('active')
->label(__('Active'))
->boolean()
->trueLabel(__('Active only'))
->falseLabel(__('Inactive only'))
->native(false),
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Clusters\Settings\Provinces\Pages;
use App\Filament\Clusters\Settings\Provinces\ProvinceResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ManageRecords;
class ManageProvinces extends ManageRecords
{
protected static string $resource = ProvinceResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Filament\Clusters\Settings\Provinces;
use App\Filament\Clusters\Settings\Provinces\Pages\ManageProvinces;
use App\Filament\Clusters\Settings\Provinces\Schemas\ProvinceForm;
use App\Filament\Clusters\Settings\Provinces\Tables\ProvincesTable;
use App\Filament\Clusters\Settings\SettingsCluster;
use App\Modules\Province\Models\Province;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
class ProvinceResource extends Resource
{
protected static ?string $model = Province::class;
protected static ?string $cluster = SettingsCluster::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedMapPin;
protected static ?string $recordTitleAttribute = 'name';
public static function getNavigationGroup(): ?string
{
return __('Branches and provinces');
}
public static function getModelLabel(): string
{
return __('module.province::base.Province');
}
public static function getPluralModelLabel(): string
{
return __('module.province::base.Provinces');
}
public static function form(Schema $schema): Schema
{
return ProvinceForm::configure($schema);
}
public static function table(Table $table): Table
{
return ProvincesTable::configure($table);
}
public static function getPages(): array
{
return [
'index' => ManageProvinces::route('/'),
];
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Filament\Clusters\Settings\Provinces\Schemas;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Schema;
class ProvinceForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Select::make('region')
->label(__('Region'))
->options(fn () => regions())
->required()
->native(false)
->searchable(),
TextInput::make('name')
->label(__('Name'))
->required()
->maxLength(255)
->translatableTabs(),
Toggle::make('active')
->label(__('Active'))
->default(true)
->required(),
]);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Filament\Clusters\Settings\Provinces\Tables;
use App\Modules\Region\Repositories\RegionRepository;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
class ProvincesTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label(__('Name'))
->searchable()
->sortable(),
TextColumn::make('region')
->label(__('Region'))
->formatStateUsing(fn (string $state): string => RegionRepository::label($state))
->searchable()
->sortable(),
IconColumn::make('active')
->label(__('Active'))
->boolean()
->sortable(),
TextColumn::make('created_at')
->label(__('Created At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->label(__('Updated At'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
SelectFilter::make('region')
->label(__('Region'))
->options(fn () => regions())
->native(false),
TernaryFilter::make('active')
->label(__('Active'))
->boolean()
->trueLabel(__('Active only'))
->falseLabel(__('Inactive only'))
->native(false),
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Filament\Clusters\Settings;
use BackedEnum;
use Filament\Clusters\Cluster;
use Filament\Pages\Enums\SubNavigationPosition;
use Filament\Support\Icons\Heroicon;
class SettingsCluster extends Cluster
{
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCog8Tooth;
protected static ?SubNavigationPosition $subNavigationPosition = SubNavigationPosition::End;
public static function getNavigationLabel(): string
{
return __('Settings');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Filament\Pages\Auth;
use Filament\Auth\Pages\EditProfile as BaseEditProfile;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class EditProfile extends BaseEditProfile
{
public function form(Schema $schema): Schema
{
return $schema
->components([
Section::make('Profile Information')
->description('Update your account\'s profile information and email address.')
->components([
TextInput::make('name')
->label('Name')
->required()
->maxLength(255)
->placeholder('Enter your full name'),
$this->getEmailFormComponent(),
]),
Section::make('Update Password')
->description('Ensure your account is using a long, random password to stay secure.')
->components([
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
]),
]);
}
}

60
app/Helpers/helpers.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
use App\Models\User;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
/**
* Filament path
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
function filament_path(): string
{
$path = config()->string('app.filament_path');
abort_if(! $path, 500, 'Filament path missing');
return $path;
}
/**
* Temprory cache for single request
*
* @return ($key is '' ? CacheRepository : mixed)
*/
function temp_cache(string $key = ''): mixed
{
$tempCache = cache()->driver('array');
return ($key === '') ? $tempCache : $tempCache->get($key);
}
/**
* Log
*/
function logDB(): void
{
if (! app()->isLocal()) {
return;
}
DB::listen(function ($query) {
Log::info($query->sql, $query->bindings, $query->time);
});
}
/**
* User
*/
function user(): User
{
abort_unless(Auth::check(), 'not-authenticated');
/** @var \App\Models\User */
$user = Auth::user();
return $user;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
abstract class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Joaopaulolndev\FilamentEditProfile\Pages\EditProfilePage;
use Symfony\Component\HttpFoundation\Response;
class EnsureProfileIsFilled
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
/** @var \App\Models\User */
$user = $request->user();
// 1. If user is not logged in, or profile is already complete, do nothing.
// (Based on your logic: must_fill_profile == true means complete)
if (! $user->must_fill_profile) {
return $next($request);
}
// 3. Define the 'safe' routes
$profilePageClass = EditProfilePage::class; // <-- !! IMPORTANT: Change to your page
$profilePageUrl = $profilePageClass::getUrl();
$panelId = filament()->getCurrentPanel()->getId();
$logoutRouteName = "filament.{$panelId}.auth.logout";
// 4. Check for 'safe' conditions
// Are they ALREADY on the profile page?
// We check the full URL to be precise.
$isProfilePage = $request->fullUrlIs($profilePageUrl);
// Are they trying to log out?
$isLoggingOut = $request->routeIs($logoutRouteName);
// Is this an internal Livewire request?
// This is the KEY to fixing the SPA redirect loop.
$isLivewireRequest = $request->is('livewire/*');
// 5. If they are on a safe route, let them proceed.
if ($isProfilePage || $isLoggingOut || $isLivewireRequest) {
return $next($request);
}
// 6. If not, redirect them to the profile page.
// Filament's SPA mode will intercept this 302 redirect
// and navigate without a full page reload.
return redirect($profilePageUrl);
}
}

View File

@@ -0,0 +1,197 @@
<?php
namespace App\Livewire;
use App\Modules\PhoneNumberVerification\Rules\PhoneNumberVerificationRule;
use App\Modules\TurkmenPassport\Repositories\TurkmenPassportRepository;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Filament\Schemas\Components\Fieldset;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Exceptions\Halt;
use Illuminate\Contracts\View\View;
use Joaopaulolndev\FilamentEditProfile\Concerns\HasSort;
use Livewire\Component;
class UserPassportFields extends Component implements HasForms
{
use HasSort;
use InteractsWithForms;
public ?array $data = [];
protected static int $sort = 10;
public function mount(): void
{
$this->form->fill();
}
public function form(Schema $schema): Schema
{
return $schema
->components([
Section::make(__('Profile Information'))
->aside()
->columns(6)
->description(__('Fill your account profile information'))
->schema([
TextInput::make('first_name')
->label(__('First name'))
->string()
->maxLength(255)
->default(user()->first_name)
->columnSpan(2)
->required(),
TextInput::make('last_name')
->label(__('Last name'))
->string()
->maxLength(255)
->default(user()->last_name)
->columnSpan(2)
->required(),
TextInput::make('patronic_name')
->label(__('Patronic name'))
->columnSpan(2)
->default(user()->getOption('patronic_name'))
->maxLength(255),
DatePicker::make('born_at')
->displayFormat('d.m.Y')
->label(__('Birth date'))
->native(false)
->default(user()->getOption('born_at'))
->columnSpan(2)
->required()
->beforeOrEqual('today'),
TextInput::make('phone')
->label(__('Phone'))
->mask('99 99 99 99')
->prefix('+993')
->rules([
new PhoneNumberVerificationRule,
])
->unique(ignoreRecord: false)
->default(user()->phone)
->columnSpan(2)
->required(),
TextInput::make('email')
->label(__('Email'))
->email()
->default(user()->email)
->columnSpan(2),
Fieldset::make(__('Passport'))
->columns([
'default' => 1,
'md' => 6,
'xl' => 6,
])
->columnSpan(6)
->schema([
Select::make('passport_serie')
->label(__('Passport serie'))
->options(TurkmenPassportRepository::values())
->native(false)
->default(user()->getOption('passport_serie'))
->required()
->columnSpan(2),
TextInput::make('passport_id')
->label(__('Passport number'))
->default(user()->getOption('passport_id'))
->required()
->columnSpan(2)
->mask('999999'),
DatePicker::make('passport_given_at')
->label(__('Passport given date'))
->columnSpan(2)
->displayFormat('d.m.Y')
->native(false)
->closeOnDateSelection()
->beforeOrEqual('today')
->default(user()->getOption('passport_given_at'))
->required(),
TextInput::make('born_place')
->columnSpan(3)
->label(__('Born place (passport)'))
->maxLength(255)
->default(user()->getOption('born_place'))
->required(),
TextInput::make('passport_given_by')
->label(__('Passport given by'))
->columnSpan(3)
->maxLength(255)
->default(user()->getOption('passport_given_by'))
->required(),
TextInput::make('passport_address')
->columnSpan(3)
->label(__('Proscription for home'))
->maxLength(255)
->default(user()->getOption('passport_address'))
->required(),
TextInput::make('real_address')
->label(__('Current home address'))
->columnSpan(3)
->maxLength(255)
->default(user()->getOption('real_address'))
->required(),
]),
]),
])
->statePath('data');
}
public function save(): void
{
try {
/** @var array{first_name: string, last_name: string, patronic_name: null|string, born_at: string, phone: string, email: string, passport_serie: string, passport_id: string, passport_given_at: string, born_place: string, passport_given_by: string, passport_address: string, real_address: string} */
$data = $this->form->getState();
user()->update([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'phone' => $data['phone'],
'email' => $data['email'],
'options->patronic_name' => $data['patronic_name'],
'options->born_at' => $data['born_at'],
'options->passport_serie' => $data['passport_serie'],
'options->passport_id' => $data['passport_id'],
'options->passport_given_at' => $data['passport_given_at'],
'options->born_place' => $data['born_place'],
'options->passport_given_by' => $data['passport_given_by'],
'options->passport_address' => $data['passport_address'],
'options->real_address' => $data['real_address'],
'must_fill_profile' => false,
]);
$this->dispatch('refresh-topbar');
} catch (Halt $exception) {
return;
}
Notification::make()
->success()
->title(__('Profile updated'))
->send();
}
public function render(): View
{
return view('livewire.user-passport-fields');
}
}

51
app/Models/User.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use App\Modules\UserAdjustments\Traits\UserAdjustments;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Date;
use Spatie\Permission\Traits\HasRoles;
/**
* @property int $id
* @property string $name
* @property null|string $email [unique]
* @property Date|null $email_verified_at
* @property string $password [hidden]
* @property string|null $remember_token
* @property Date|null $created_at
* @property Date|null $updated_at
*/
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory;
use HasRoles;
use Notifiable;
use UserAdjustments;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Modules\AppHelpers;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class AppHelpersModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Modules\AppHelpers\Repositories;
class CacheRepository
{
/**
* Cache name
*/
protected string $name;
/**
* Value
*/
protected mixed $value;
/**
* Time
*/
protected int $time;
/**
* Cache repo
*/
public function __construct(string $name, mixed $value, int $time = 600)
{
$this->name = $name;
$this->value = $value;
$this->time = $time;
}
/**
* Cache Repo
*
* @param string $name key
* @param mixed $value value
* @param int|int $time time in seconds
*/
public static function make(string $name, mixed $value, int $time = 600): mixed
{
$repo = new self($name, $value, $time);
return $repo->handle();
}
/**
* Handle cache
*/
public function handle(): mixed
{
return cache()->has($this->name)
? cache($this->name)
: cache()->remember(
key: $this->name,
ttl: $this->time,
callback: fn () => is_callable($this->value) ? call_user_func($this->value) : $this->value
);
}
/**
* Forget the key from cache
*/
public static function forget(string $name): void
{
cache()->forget($name);
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace App\Modules\BaseAuth;
use App\Modules\Core\ModulePackage;
use App\Modules\Core\ModulePackageType;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class BaseAuthModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [
new ModulePackage(
type: ModulePackageType::PACKAGE,
name: 'laravel/ui',
message: 'Required for authentication scaffolding.',
),
];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [
new ModulePackage(
type: ModulePackageType::MODULE,
name: 'BaseLocale',
message: 'Good for multiple language support.',
),
];
}
}

View File

@@ -0,0 +1,22 @@
<?php
return [
// Redirect path after login, register, reset password, etc.
'redirect_path' => filament_path(),
// Default username, send from request and for validation, also db column
'default_username' => 'username',
// If multiple usernames are supported for login, will be searched by user columns
'multiple_usernames' => true,
'usernames' => [
'username',
'phone',
],
// If auth events should be stored
'store_auth_events' => true,
// If sms verification is enabled, will be sent to the user
'sms_verification' => true,
];

View File

@@ -0,0 +1,184 @@
<?php
namespace App\Modules\BaseAuth\Controllers;
use App\Models\User;
use App\Modules\BaseLocale\Middleware\SetLocale;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class LoginController extends Controller
{
use AuthenticatesUsers, ValidatesRequests;
/**
* Middleware
*/
public function __construct()
{
$middleware = [];
if (module('BaseLocale')->isEnabled()) {
array_push($middleware, SetLocale::class);
}
$this->middleware($middleware)->except('logout');
}
/**
* Get the login username to be used by the controller, also send via request.
*/
public function username(): string
{
return config()->string('module.base-auth.default_username');
}
/**
* Supports multiple usernames
*/
public function supportsMultipleUsernames(): bool
{
return config()->boolean('module.base-auth.multiple_usernames');
}
/**
* Supports multiple usernames
*
* @return array<int, string>
*/
public function usernames(): array
{
/** @var array<int, string> */
$usernames = config()->array('module.base-auth.usernames');
return $usernames;
}
/**
* Show the application's login form.
*/
public function showLoginForm(): View
{
return view('module.base-auth::pages.login');
}
/**
* The user has been authenticated.
*/
protected function authenticated(Request $request, User $user): JsonResponse|RedirectResponse
{
$redirect = redirect()->intended($this->redirectPath());
return $request->wantsJson()
? new JsonResponse([
'redirect' => $redirect->getTargetUrl(),
], 200)
: $redirect;
}
/**
* Log the user out of the application.
*/
public function logout(Request $request): RedirectResponse
{
$this->guard()->logout();
$request->session()->invalidate();
return redirect()->intended($this->redirectPath());
}
/**
* Get the post register / login redirect path.
*/
public function redirectPath(): string
{
return config()->string('module.base-auth.redirect_path');
}
/**
* Validate the user login request.
*
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function validateLogin(Request $request): void
{
$request->validate([
$this->username() => ['required', 'string', 'max:250'],
'password' => ['required', 'string', 'max:250'],
]);
}
/**
* Handle a login request to the application.
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
*/
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if (method_exists($this, 'hasTooManyLoginAttempts') && $this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
$user = User::query()
->when($this->supportsMultipleUsernames(), function ($query) use ($request) {
foreach ($this->usernames() as $username) {
$query->orWhere($username, $request->username);
}
}, function ($query) use ($request) {
$query->where($this->username(), $request->username);
})
->first();
if (! $user) {
return $this->sendFailedLoginResponse($request);
}
if (Hash::check($request->string('password'), $user->password)) {
Auth::login($user);
if ($request->hasSession()) {
$request->session()->put('auth.password_confirmed_at', time());
}
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
/**
* Send the response after the user was authenticated.
*/
protected function sendLoginResponse(Request $request): RedirectResponse|JsonResponse
{
$request->session()->regenerate();
$this->clearLoginAttempts($request);
return $this->authenticated($request, $this->guard()->user()); // @phpstan-ignore-line
}
}

View File

@@ -0,0 +1,173 @@
<?php
namespace App\Modules\BaseAuth\Controllers;
use App\Http\Controllers\Controller;
use App\Models\System\Verification;
use App\Models\User;
use App\Modules\BaseAuth\Models\AuthEvent;
use App\Modules\BaseLocale\Middleware\SetLocale;
use App\Modules\OtpVerification\Rules\OtpVerificationRule;
use App\Modules\PhoneNumberVerification\Rules\PhoneNumberVerificationRule;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/**
* Middleware
*/
public function __construct()
{
$middleware = [];
if (module('BaseLocale')->isEnabled()) {
array_push($middleware, SetLocale::class);
}
$this->middleware($middleware)->except('logout');
}
/**
* Show registration page
*/
public function showNovaRegisterpageForm(): View
{
return view('module.base-auth::pages.register');
}
/**
* Handle a registration request for the application.
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function register(Request $request)
{
if ($request->has('phone')) {
$request->merge([
'phone' => unMaskTurkmenNumber($request->string('phone')),
]);
}
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
Auth::guard()->login($user);
if (config('module.base-auth.store_auth_events')) {
storeAuthEvent(AuthEvent::REGISTER, $request);
}
if (config('module.base-auth.sms_verification')) {
sendSMSVerification((string) $user->phone);
return response()->json([
'url' => route('sms-verification'),
]);
}
return response()->json([
'url' => config('module.base-auth.redirect_path'),
]);
}
/**
* Get a validator for an incoming registration request.
*
* @param array<string, int|string> $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'phone' => ['required', new PhoneNumberVerificationRule, 'unique:users,phone'],
'username' => ['required', 'string', 'alpha_dash:ascii', 'max:255', 'unique:users,username'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array<string, int|string> $data
* @return \App\Models\User
*/
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'phone' => $data['phone'],
'username' => $data['username'],
'password' => Hash::make((string) $data['password']),
'must_fill_profile' => true,
]);
return $user;
}
/**
* Sms verification
*/
public function smsVerification(): View
{
return view('module.base-auth::pages.sms-verification', ['phone' => Auth::user()?->phone]);
}
/**
* Change users phone number
*/
public function changePhone(Request $request): JsonResponse
{
if ($request->has('phone')) {
$request->merge(['phone' => unMaskTurkmenNumber($request->string('phone'))]);
}
$request->validate([
'phone' => ['required', new PhoneNumberVerificationRule, 'unique:users,phone'],
]);
/** @var User */
$user = Auth::user();
$user->update([
'phone' => $request->phone,
]);
storeAuthEvent(AuthEvent::PHONE_CHANGED, $request);
sendSMSVerification((string) $user->phone);
return response()->json([
'url' => route('sms-verification'),
]);
}
/**
* Verify sms code
*/
public function verifySmsCode(Request $request): RedirectResponse
{
/** @var User */
$user = Auth::user();
$request->validate([
'code' => ['bail', 'required', 'integer', new OtpVerificationRule($user->phone)],
]);
$user->update([
'phone_verified_at' => now(),
]);
storeAuthEvent(AuthEvent::PHONE_VERIFICATION, $request);
return redirect(config()->string('module.base-auth.redirect_path'));
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace App\Modules\BaseAuth\Controllers;
use App\Http\Controllers\Controller;
use App\Models\System\Verification;
use App\Models\User;
use App\Modules\BaseAuth\Models\AuthEvent;
use App\Modules\OtpVerification\Models\OtpVerification;
use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
class ResetPasswordController extends Controller
{
/**
* Reset password page
*/
public function index(): View
{
return view('module.base-auth::pages.reset-password');
}
/**
* Store new password
*/
public function store(Request $request): JsonResponse
{
$request->validate([
'username' => ['required', 'string', 'max:250', 'exists:users,username'],
'verification' => ['nullable', 'integer', Rule::requiredIf(fn () => $request->filled('step-verification'))],
'step-sms' => ['nullable'],
'step-verification' => ['nullable'],
'step-password' => ['nullable'],
'password' => ['bail', 'nullable', 'string', 'min:8', 'confirmed', Rule::requiredIf(fn () => $request->filled('step-password'))],
]);
/** @var User */
$user = User::where('username', $request->username)->first();
if ($request->filled('step-sms') && $request->isNotFilled('step-verification') && $request->isNotFilled('step-password')) {
return $this->sendVerification($request, $user);
}
if ($request->filled('step-verification') && $request->isNotFilled('step-password')) {
return $this->verify($request, $user);
}
if ($request->filled('step-password')) {
return $this->updatePassword($request, $user);
}
return response()->json();
}
/**
* Send verification code
*/
public function sendVerification(Request $request, User $user): JsonResponse
{
sendSMSVerification((string) $user->phone);
return response()->json([
'step' => 1,
'message' => __('We send you a verification code to').' ****'.substr((string) $user->phone, 4),
]);
}
/**
* Verify phone number
*/
public function verify(Request $request, User $user): JsonResponse
{
$verification = OtpVerification::where('username', $user->phone)
->where('code', $request->verification)
->first();
if (! $verification) {
return response()->json([
'errors' => [
'verification' => [
__('Incorrect verification code'),
],
],
'message' => __('Incorrect verification code'),
]);
}
return response()->json([
'step' => 2,
'message' => __("Now you can set your password, but please make sure that you don't forget it!"),
]);
}
/**
* Update password
*/
public function updatePassword(Request $request, User $user): JsonResponse
{
$user->update(['password' => bcrypt($request->string('password'))]);
storeAuthEvent(AuthEvent::PASSWORD_RESET, request());
return response()->json([
'step' => 3,
'message' => __('Your password has been updated'),
]);
}
}

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('auth_events', function (Blueprint $table) {
$table->id();
$table->string('name')->index();
$table->string('request_method')->index();
$table->string('ip')->nullable()->index();
$table->string('user_agent')->nullable()->index();
$table->string('target_url')->nullable()->index();
$table->json('options')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('auth_events');
}
};

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Modules\BaseAuth\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class RedirectIfUserPhoneIsUnVerfied
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check() && is_null($request->user()?->phone_verified_at)) {
return redirect()->route('sms-verification');
}
return $next($request);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Modules\BaseAuth\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class RedirectIfUserPhoneIsVerfied
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check() && ! is_null($request->user()?->phone_verified_at)) {
return redirect()->route(config()->string('module.base-auth.redirect_path'));
}
return $next($request);
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace App\Modules\BaseAuth\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
/**
* @property int $id
* @property string $name
* @property string $request_method
* @property string|null $ip
* @property string|null $user_agent
* @property string|null $target_url
* @property string|null $options
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
class AuthEvent extends Model
{
protected $table = 'auth_events';
/**
* When user registers to application
*/
public const REGISTER = 'REGISTER';
/**
* When user logs into application
*/
public const LOGIN = 'LOGIN';
/**
* When user verifies phone number
*/
public const PHONE_VERIFICATION = 'PHONE_VERIFICATION';
/**
* When user verifies phone number
*/
public const PHONE_CHANGED = 'PHONE_CHANGED';
/**
* When user logs out of application
*/
public const LOGOUT = 'LOGOUT';
/**
* When user resets password
*/
public const PASSWORD_RESET = 'PASSWORD_RESET';
/**
* When user resets password
*/
public const FAILED = 'FAILED';
/**
* When user resets password
*/
public const ATTEMPTING = 'ATTEMPTING';
/**
* When user resets password
*/
public const LOCKOUT = 'LOCKOUT';
/**
* Laravel's default events
*
* @return array<string, string>
*/
public static function laravelDefaultEvents(): array
{
return [
'Illuminate\\Auth\\Events\\Attempting' => self::ATTEMPTING,
'Illuminate\\Auth\\Events\\Failed' => self::FAILED,
'Illuminate\\Auth\\Events\\Lockout' => self::LOCKOUT,
];
}
/**
* Guest the event
*/
public static function guessEvent(string|object $event): string
{
if (is_object($event)) {
$event = get_class($event);
}
return self::laravelDefaultEvents()[$event] ?? '';
}
/**
* Log type
*/
public static function logType(string $name): string
{
return match ($name) {
self::REGISTER => 'notice',
self::LOGIN => 'notice',
self::PHONE_VERIFICATION => 'info',
self::LOGOUT => 'notice',
self::PASSWORD_RESET => 'info',
self::FAILED => 'warning',
self::ATTEMPTING => 'alert',
self::LOCKOUT => 'alert',
default => 'info',
};
}
}

View File

@@ -0,0 +1,16 @@
<?php
return [
'online_panel' => 'Online panel',
'login' => 'Login',
'register' => 'Register',
'reset_password' => 'Reset password',
'help' => 'Help',
'privacy_policy' => 'Privacy policy',
'phone' => 'Phone',
'username' => 'Username',
'or' => 'or',
'continue' => 'Continue',
'successfully_logged_in' => 'Successfully logged in',
'press_continue' => 'Press continue',
];

View File

@@ -0,0 +1,5 @@
<?php
return [
];

View File

@@ -0,0 +1,32 @@
<?php
return [
'online_panel' => 'Onlaýn kabulhana',
'login' => 'Giriş',
'register' => 'Agza bolmak',
'reset_password' => 'Açar sözüni ýatdan çykardyňyzmy?',
'help' => 'Kömek',
'privacy_policy' => 'Gizlinlik syýasaty',
'phone' => 'Telefon',
'username' => 'ulanyjy ady',
'password' => 'Açar sözi',
'or' => 'ýada',
'continue' => 'Dowam etmek',
'successfully_logged_in' => 'Üstünlik bilen girdiňiz',
'press_continue' => 'Dowam etmek düwme basyň',
'please_wait_while_we_redirect_you_to_your_personal_account' => 'Şahsy hasabyňyza geçýänçä garaşyň',
'forgot_your_password' => 'Açar sözüni unutdyňyzmy?',
'successfully_registered' => 'Üstünlikli hasaba alyndyňyz',
'please_now_verify_your_phone_number_to_continue' => 'Dowam etmek üçin telefon belgiňizi tassyklaň',
'go_to_login_page' => 'Giriş sahypasyyna geçiň',
'full_name' => 'Adyňyz',
'confirm_password' => 'Açar sözi tassyklaňyz',
'verify_phone_number' => 'Telefon beligiňizi tassyklaň',
'verification_code' => 'Tassyklaýyş belgi',
'submit' => 'Tassyklamak',
'verification_code_has_been_send_to_number' => 'Tassyklaýyş belgi telefon belgisine ugradyldy',
'change_number' => 'Üýtget',
'change_phone_label' => 'Telefon belgini üýtgetmek',
'go_back' => 'Yza',
'successfully_changed_phone' => 'Telefon belgiňiz üýtgedildi',
];

View File

@@ -0,0 +1,79 @@
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}" dir="ltr" class="h-full font-sans antialiased">
<head>
<meta name="theme-color" content="#fff">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width"/>
<meta name="locale" content="tk"/>
<meta name="robots" content="noindex">
<link rel="shortcut icon" href="/favicon.png" type="image/png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<!-- Styles -->
<link rel="stylesheet" href="/assets/css/auth-layout.css">
<link rel="stylesheet" href="/assets/css/auth.css">
<link rel="stylesheet" href="/assets/css/cookieconsent.css">
</head>
<body>
<div>
<div class="bg-white flex justify-between px-4 py-1 absolute w-full shadow-none shadow-lg">
<div class="px-8 text-sm p-1 rounded uppercase font-bold padding-none">
<a href="#" class="d-none-copyright"> “Türkmenbaşy” PTB © </a>
</div>
<div class="flex items-center">
<a href="tel:+99312444234" class="mr-6 text-sm text-gray-900">(+99312) 44-42-34</a>
<a href="#" class="mr-6 text-sm text-gray-900 uppercase">{{ __('module.base-auth::base.help') }}</a>
<div class="flex text-sm text-gray-90a0 space-x-1 uppercase">
@if (module('BaseLocale')->isEnabled())
@foreach(baseLocales() as $localeKey => $localeDisplayName)
<a
href="{{ route('module.base-locale.set-locale', ['locale' => $localeKey]) }}"
class="{{ app()->getLocale() === $localeKey ? 'font-bold' : '' }}"
>
{{ $localeKey }}
@unless($loop->last)
|
@endif
</a>
@endforeach
@endif
</div>
</div>
</div>
<div class="login-section d-center items-center h-screen">
<div class="d-none h-full max-w-4xl">
<img src="/assets/images/bank-img.PNG" class="h-full object-cover">
</div>
<div class="relative">
@yield('content')
<div class="text-center relative" style="top: 4em;">
<a href="/privacy-policy.pdf" class="text-gray-500 font-bold text-underline" target="_blank">
{{ __('module.base-auth::base.privacy_policy') }}
</a>
</div>
</div>
</div>
</div>
<script src="/assets/js/inputmask.min.js"></script>
<script src="/assets/js/sweetalert2.js"></script>
<script src="/assets/js/cookieconsent.js"></script>
<script src="/assets/js/fn.js"></script>
<script src="/assets/js/app.js"></script>
@stack('js')
</body>
</html>

View File

@@ -0,0 +1,88 @@
@extends('module.base-auth::layouts.auth-layout')
@push('js')
<script>
async function login(event) {
const response = await postData(event.target.action, getFormData(event))
console.log(response)
if (response.errors) {
loopObject(response.errors, item => addValidationClasses(item))
return;
}
removeValidationClasess()
await Swal.fire({
title: '{{ __('module.base-auth::base.successfully_logged_in') }}',
text: '{{ __('module.base-auth::base.press_continue') }}',
confirmButtonText: '{{ __('module.base-auth::base.continue') }}',
icon: 'success',
showDenyButton: false,
showCancelButton: false,
})
window.location.href = '{{ route('login') }}'
}
</script>
@endpush
@section('content')
<form
method="POST"
action="{{ route('login') }}"
onsubmit="event.preventDefault();login(event)"
class="bg-white dark:bg-gray-800 rounded-lg p-8 w-[25rem] mx-auto"
>
@csrf
<h2 class="text-2xl text-center font-normal mb-6 uppercase">{{ __('module.base-auth::base.online_panel') }}</h2>
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
</svg>
<div class="mb-6">
<label class="block mb-2" for="username">
{{ __('module.base-auth::base.phone') }} {{ __('module.base-auth::base.or') }} <span class="lowecase">{{ __('module.base-auth::base.username') }}</span>
</label>
<input class="form-control form-input form-input-bordered w-full"
id="username"
type="text"
name="username"
placeholder="+99365999990 {{ __('or') }} {{ __('module.base-auth::base.username') }}"
autofocus=""
value="{{ old('username') }}"
>
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="mb-6">
<label class="block mb-2" for="password">
{{ __('module.base-auth::base.password') }}
</label>
<input
class="form-control form-input form-input-bordered w-full"
id="password"
type="password"
name="password"
>
<span id="password-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="flex mb-6">
<div class="ml-auto">
<a href="{{ route('reset-password') }}" class="text-gray-500 font-bold no-underline">
{{ __('module.base-auth::base.forgot_your_password') }}
</a>
</div>
</div>
<button class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center" type="submit">
<span class=""><span>{{ __('module.base-auth::base.login') }}</span></span>
</button>
<a href="{{ route('register') }}" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
<span class=""><span>{{ __('module.base-auth::base.register') }}</span></span>
</a>
</form>
@stop

View File

@@ -0,0 +1,124 @@
@extends('module.base-auth::layouts.auth-layout')
@push('js')
<script>
async function register(event) {
const response = await postData(event.target.action, getFormData(event))
if (response.errors) {
loopObject(response.errors, item => addValidationClasses(item))
return;
}
removeValidationClasess()
console.log(response)
await Swal.fire({
title: '{{ __('module.base-auth::base.successfully_registered') }}',
text: '{{ __('module.base-auth::base.please_now_verify_your_phone_number_to_continue') }}',
icon: 'success',
showDenyButton: false,
showCancelButton: false,
})
window.location.href = response.url;
}
</script>
@endpush
@section('content')
<form
class="bg-white dark:bg-gray-800 rounded-lg p-8 w-[25rem] mx-auto mt-1"
method="POST"
action="{{ route('register') }}"
onsubmit="event.preventDefault();register(event)"
>
@csrf
<h2 class="text-2xl text-center font-normal mb-6">{{ __('module.base-auth::base.online_panel') }}</h2>
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
</svg>
<div class="mb-1">
<label class="block mb-1" for="name">
{{ __('module.base-auth::base.full_name') }}
</label>
<input class="form-control form-input form-input-bordered w-full"
id="name"
type="text"
name="name"
autofocus=""
value="{{ old('name') }}"
>
<span id="name-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="mb-1">
<label class="block mb-1" for="phone">
{{ __('module.base-auth::base.phone') }}
</label>
<input class="form-control form-input form-input-bordered w-full"
id="phone"
type="text"
name="phone"
autofocus=""
value="{{ old('phone') }}"
>
<span id="phone-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="mb-1">
<label class="block mb-1" for="username">
{{ ucfirst(__('module.base-auth::base.username')) }}
</label>
<input class="form-control form-input form-input-bordered w-full"
id="username"
type="text"
name="username"
autofocus=""
value="{{ old('username') }}"
>
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="mb-1">
<label class="block mb-1" for="password">
{{ __('module.base-auth::base.password') }}
</label>
<input class="form-control form-input form-input-bordered w-full"
id="password"
type="password"
name="password"
>
<span id="password-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="mb-1">
<label class="block mb-1" for="password_confirmation">
{{ __('module.base-auth::base.confirm_password') }}
</label>
<input class="form-control form-input form-input-bordered w-full"
id="password_confirmation"
type="password"
name="password_confirmation"
>
<span id="password_confirmation-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="mb-6"></div>
<button
class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center"
type="submit"
>
<span class=""><span>{{ __('module.base-auth::base.register') }}</span></span>
</button>
<a
href="{{ route('login') }}"
class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center"
>
<span class=""><span>{{ __('module.base-auth::base.go_to_login_page') }}</span></span>
</a>
</form>
@stop

View File

@@ -0,0 +1,104 @@
@extends('module.base-auth::layouts.auth-layout')
@push('js')
<script>
async function resetPassword(event) {
const response = await postData(event.target.action, getFormData(event))
if (response.errors) {
loopObject(response.errors, item => addValidationClasses(item))
} else {
removeValidationClasess()
if (response.step === 1) {
showVerificationCodeBox()
Swal.fire({
title: '{{ __('Verification code') }}',
text: response.message,
icon: 'info'
})
}
if (response.step === 2) {
showPasswordBox()
Swal.fire({
title: '{{ __('Reset Password') }}',
text: response.message,
icon: 'warning'
})
}
if (response.step === 3) {
await Swal.fire({
title: response.message,
showDenyButton: false,
showCancelButton: false,
})
window.location.href = '{{ route('login') }}'
}
}
}
</script>
@endpush
@section('content')
<form
method="POST"
action="{{ route('reset-password') }}"
onsubmit="event.preventDefault();resetPassword(event)"
class="bg-white dark:bg-gray-800 rounded-lg p-8 w-[25rem] mx-auto"
>
@csrf
<h2 class="text-2xl text-center font-normal mb-6">{{ __('Enter your username to continue') }}</h2>
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
</svg>
<div id="username-box" class="mb-6">
<label class="block mb-2" for="username">
{{ __('Username') }}
</label>
<input
id="username"
type="text"
name="username"
class="form-control form-input form-input-bordered w-full"
autofocus=""
>
<input type="hidden" name="step-sms" value="1">
<span id="username-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<div class="mb-6 hidden" id="verification-code-box">
<label class="block mb-2" for="verification">
{{ __('Verification code') }}
</label>
</div>
<div class="hidden" id="reset-password-container">
<div class="mb-6" id="password-box">
<label class="block mb-2" for="password">
{{ __('Password') }}
</label>
</div>
<div class="mb-6" id="password-confirm-box">
<label class="block mb-2" for="password_confirmation">
{{ __('Confirm Password') }}
</label>
</div>
</div>
<button class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center" type="submit">
<span class=""><span>{{ __('Submit') }}</span></span>
</button>
<a href="{{ route('register') }}" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
<span class=""><span>{{ __('Go to login page') }}</span></span>
</a>
</form>
@stop

View File

@@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="tk" dir="ltr" class="h-full font-sans antialiased">
<head>
<meta name="theme-color" content="#fff">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width"/>
<meta name="locale" content="tk"/>
<meta name="robots" content="noindex">
<!-- Styles -->
<link rel="stylesheet" href="/assets/css/auth-layout.css">
<style>
.bg-secondary-500 {
background-color: rgb(186,230,253);
}
.hover:bg-secondary-400 {
background-color: rgba(24, 182, 155, 0.5);
}
.underline {
text-decoration: underline;
}
.d-none {
display: none;
}
</style>
</head>
<body class="min-w-site text-sm font-medium min-h-full text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-900">
<div class="py-6 px-1 md:px-2 lg:px-6">
<div class="mx-auto py-8 max-w-sm flex justify-center">
<span class="uppercase text-4xl">{{ __('module.base-auth::base.online_panel') }}</span>
</div>
<div class="bg-white dark:bg-gray-800 shadow rounded-lg p-8 max-w-[25rem] mx-auto">
<h2 class="text-2xl text-center font-normal mb-6">{{ __('module.base-auth::base.verify_phone_number') }}</h2>
<div class="flex justify-center items-center mb-6">
<h2 class="text-lg text-center font-normal mr-4">+993 {{ $phone }}</h2>
<span href="#" class="underline cursor-pointer" onclick="showChangePhone()" id="change-phone-button">
{{ __('module.base-auth::base.change_number') }}
</span>
<span href="#" class="underline cursor-pointer d-none" onclick="goBack()" id="go-back-button">
{{ __('module.base-auth::base.go_back') }}
</span>
</div>
{{-- Border line --}}
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
<path fill="#D8E3EC" d="M0 0h100v2H0z"></path>
</svg>
{{-- Change phone form --}}
<form method="POST" action="{{ route('change-phone') }}" id="change-phone-form" class="d-none" onsubmit="event.preventDefault();changePhone(event)">
@csrf
<div class="mb-6">
<label class="block mb-2" for="phone">
{{ __('module.base-auth::base.change_phone_label') }}
</label>
<input class="form-control form-input form-input-bordered w-full" id="phone" type="text" name="phone" required="">
<span id="phone-error-box" class="text-red-500 text-italic error-box"></span>
</div>
<button type="submit" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
<span class=""><span>{{ __('module.base-auth::base.change_number') }}</span></span>
</button>
</form>
{{-- Verification form --}}
<form method="POST" action="{{ route('sms-verification') }}" id="verification-form">
@csrf
<div class="mb-6">
<label class="block mb-2" for="code">
{{ __('module.base-auth::base.verification_code') }}
</label>
<input class="form-control form-input form-input-bordered w-full" id="code" type="number" name="code" required="">
@if($errors->any())
@foreach($errors->all() as $error)
<p class="mt-2 text-red-500">{{ $error }}</p>
@endforeach
@endif
</div>
<button type="submit" class="w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center cursor-pointer rounded text-sm font-bold focus:outline-none focus:ring ring-primary-200 dark:ring-gray-600 inline-flex items-center justify-center h-9 px-3 mb-3 w-full flex justify-center shadow relative bg-primary-500 hover:bg-primary-400 text-white dark:text-gray-900 w-full flex justify-center">
<span class=""><span>{{ __('module.base-auth::base.submit') }}</span></span>
</button>
</form>
</div>
</div>
<script src="/assets/js/inputmask.min.js"></script>
<script src="/assets/js/sweetalert2.js"></script>
<script src="/assets/js/fn.js"></script>
<script>
let phoneField = $_ID('phone')
let changePhoneform = $_ID('change-phone-form')
let verificationForm = $_ID('verification-form')
let changePhoneButton = $_ID('change-phone-button')
let goBackButton = $_ID('go-back-button')
ready(() => {
new Inputmask("+(\\9\\93)-99-99-99-99").mask(phoneField);
})
async function goBack() {
hide(changePhoneform)
show(changePhoneButton)
hide(goBackButton)
show(verificationForm)
}
function showChangePhone() {
show(changePhoneform)
hide(changePhoneButton)
show(goBackButton)
hide(verificationForm)
}
async function changePhone(event) {
const response = await postData(event.target.action, getFormData(event))
if (response.errors) {
loopObject(response.errors, item => addValidationClasses(item))
return;
}
removeValidationClasess()
await Swal.fire({
title: '{{ __('module.base-auth::base.successfully_changed_phone') }}',
text: '{{ __('module.base-auth::base.please_now_verify_your_phone_number_to_continue') }}',
icon: 'success',
showDenyButton: false,
showCancelButton: false,
})
window.location.href = response.url;
}
</script>
</body>
</html>

View File

@@ -0,0 +1,28 @@
<?php
use App\Modules\BaseAuth\Controllers\LoginController;
use App\Modules\BaseAuth\Controllers\RegisterController;
use App\Modules\BaseAuth\Controllers\ResetPasswordController;
use App\Modules\BaseAuth\Middleware\RedirectIfUserPhoneIsVerfied;
use Illuminate\Support\Facades\Route;
Route::middleware(['web', 'guest'])->group(function () {
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('/login', [LoginController::class, 'login']);
Route::get('/register', [RegisterController::class, 'showNovaRegisterpageForm'])->name('register');
Route::post('/register', [RegisterController::class, 'register']);
Route::get('reset-password', [ResetPasswordController::class, 'index'])->name('reset-password');
Route::post('reset-password', [ResetPasswordController::class, 'store']);
});
Route::middleware(['web', 'auth', RedirectIfUserPhoneIsVerfied::class])->group(function () {
Route::post('change-phone', [RegisterController::class, 'changePhone'])->name('change-phone');
Route::get('sms-verification', [RegisterController::class, 'smsVerification'])
->name('sms-verification');
Route::post('sms-verification', [RegisterController::class, 'verifySmsCode']);
});

View File

@@ -0,0 +1,48 @@
<?php
use App\Modules\BaseAuth\Models\AuthEvent;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
/**
* Store auth event
*/
function storeAuthEvent(string $name, Request $request): void
{
try {
AuthEvent::create([
'name' => $name,
'request_method' => $request->method(),
'ip' => $request->ip(),
'user_agent' => $request->userAgent(),
'target_url' => $request->url(),
'options' => json_encode($request->all()),
]);
Config::set('logging.channels.auth_activity', [
'driver' => 'single',
'path' => storage_path('logs/auth_activity.log'),
'level' => 'debug',
]);
Log::channel('auth_activity')
->{AuthEvent::logType($name)}(sprintf(
'%s, APP_NAME: %s, REQUEST_TYPE: %s, SOURCE_IP: %s, SOURCE_PORT: %s, SOURCE_URL: %s, DESTINATION_IP: %s, DESTINATION_PORT: %s, DESTINATION_COUNTRY: %s, USER_ID: %s',
$name,
config()->string('app.name'),
$request->method(),
$request->ip(),
$_SERVER['REMOTE_PORT'], // @phpstan-ignore-line
$request->url(),
$request->host(),
$request->getPort(),
(module('IpStack')->isEnabled()) ? getCountryCodeFromIp($request->ip()) : 'TM',
$request->user()->id ?? '-',
));
} catch (Exception $e) {
Log::error('could-not-store-auth-event', [
'message' => $e->getMessage(),
]);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Modules\BaseLocale;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class BaseLocaleModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,9 @@
<?php
return [
'locales' => [
'tk' => 'Türkmen',
'en' => 'English',
'ru' => 'Русский',
],
];

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Modules\BaseLocale\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
class BaseLocaleController extends Controller
{
/**
* Invoke the controller
*/
public function index(string $locale): RedirectResponse
{
if (array_key_exists($locale, baseLocales())) {
session()->put('locale', $locale);
}
return safe_back();
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Modules\BaseLocale\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class SetLocale
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check()) {
/** @var \App\Models\User */
$user = $request->user();
if (array_key_exists($user->locale ?? '', baseLocales())) {
app()->setLocale($user->locale);
}
} else {
/** @var string */
$locale = session('locale') ?: config()->string('app.locale');
app()->setLocale($locale);
}
return $next($request);
}
}

View File

@@ -0,0 +1,8 @@
<?php
use App\Modules\BaseLocale\Controllers\BaseLocaleController;
use Illuminate\Support\Facades\Route;
Route::name('module.base-locale.')->middleware(['web', 'guest'])->group(function () {
Route::get('locale/{locale}', [BaseLocaleController::class, 'index'])->name('set-locale');
});

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Http\RedirectResponse;
if (! function_exists('baseLocales')) {
/**
* Application locales
*
* @return array<string, string>
*/
function baseLocales(): array
{
/** @var array<string, string> */
$locales = config()->array('module.base-locale.locales');
return $locales;
}
}
if (! function_exists('safe_back')) {
/**
* Safe back
*/
function safe_back(string $fallback = '/'): RedirectResponse
{
$back = url()->previous();
// Allow only your own domain
if (! str_starts_with($back, config()->string('app.url'))) {
return redirect($fallback);
}
return redirect()->to($back);
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Modules;
class BaseModule
{
public function __construct(
public string $path,
public string $name,
public ModuleContract $app,
public bool $enabled = false,
) {
$this->enabled = $this->app->isEnabled();
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Modules\Branch;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class BranchModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Modules\Branch\Controllers;
use App\Http\Controllers\Controller;
use App\Modules\Branch\Models\Branch;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class BranchController extends Controller
{
/**
* LIST branches
*
* Bank şahamçalary. http://online.tbbank.gov.tm/work-place/resources/branches
*/
public function index(Request $request): JsonResponse
{
$request->validate([
'groupBy' => ['nullable', 'string', 'in:region'],
]);
$branches = Branch::query()
->where('active', true)
->get()
->map(fn ($branch) => [
'id' => $branch->id,
'name' => $branch->name,
'region' => $branch->region,
]);
if ($request->filled('groupBy')) {
$branches = $branches->groupBy('region');
}
return response()->json($branches);
}
}

View File

@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('branches', function (Blueprint $table) {
$table->id();
$table->string('unique_code')->nullable()->unique();
$table->json('name');
$table->json('address')->nullable();
$table->string('region', 2)->index();
$table->foreignId('province_id')->nullable()->constrained('provinces')->onDelete('restrict');
$table->json('phone_numbers')->nullable();
$table->string('billing_username')->nullable();
$table->string('billing_password')->nullable();
$table->string('billing_swift_username')->nullable();
$table->string('billing_swift_password')->nullable();
$table->string('billing_visa_master_username')->nullable();
$table->string('billing_visa_master_password')->nullable();
$table->string('billing_sber_username')->nullable();
$table->string('billing_sber_password')->nullable();
$table->boolean('active')->default(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('branches');
}
};

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('branch_user', function (Blueprint $table) {
$table->id();
$table->foreignId('branch_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('branch_user');
}
};

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Modules\Branch\Interfaces;
/**
* @property int $id
* @property int $branch_id
*
* @phpstan-require-extends \Illuminate\Database\Eloquent\Model
*/
interface BelongsToBranch {}

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Modules\Branch\Models;
use App\Models\User;
use App\Modules\Province\Models\Province;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Spatie\Translatable\HasTranslations;
/**
* @property int $id
* @property string $unique_code
* @property array<string, string> $name
* @property array<string, string>|null $address
* @property string $region
* @property int|null $province_id
* @property array<string, string>|null $phone_numbers
* @property string|null $billing_username
* @property string|null $billing_password
* @property string|null $billing_swift_username
* @property string|null $billing_swift_password
* @property string|null $billing_visa_master_username
* @property string|null $billing_visa_master_password
* @property string|null $billing_sber_username
* @property string|null $billing_sber_password
* @property bool $active
* @property \Illuminate\Support\Carbon $created_at
* @property \Illuminate\Support\Carbon $updated_at
*/
class Branch extends Model
{
use HasTranslations;
/**
* Table name
*
* @var string
*/
protected $table = 'branches';
/**
* Translatable fields
*
* @var array<int, string>
*/
public $translatable = [
'name',
'address',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'active' => 'boolean',
'phone_numbers' => 'array',
];
/**
* Province relationship
*
* @return BelongsTo<Province, $this>
*/
public function province(): BelongsTo
{
return $this->belongsTo(Province::class);
}
/**
* Branches associated with user
*/
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace App\Modules\Branch\Repositories;
class BranchRepository {}

View File

@@ -0,0 +1,6 @@
<?php
return [
'branch' => 'Şahamça',
'branches' => 'Şahamçalar',
];

View File

@@ -0,0 +1,313 @@
<?php
namespace App\Modules\Core\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Database\Migrations\MigrationCreator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
class MakeModule extends Command implements PromptsForMissingInput
{
/**
* Filesystem instance
*/
protected Filesystem $files;
/**
* Module name
*/
protected string $moduleName;
/**
* Module directory path
*/
protected string $moduleDirectory;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:module {module} {--plain : Create a plain module structure without default files}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create new module';
/**
* Prompt for missing input arguments using the returned questions.
*
* @return array<string, array<int, string>>
*/
protected function promptForMissingArgumentsUsing(): array
{
return [
'module' => ['Module name', 'News, Product, Order...'],
];
}
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Filesystem $files)
{
parent::__construct();
$this->files = $files;
}
/**
* Execute the console command.
*/
public function handle(): void
{
/* @var string */
$module = $this->argument('module');
$this->moduleName = $module;
$this->moduleDirectory = modules_path($module.'/');
// Create module directory if not exists...
$this->makeDirectory($this->moduleDirectory);
// Make a module file...
$this->makeModuleFile($this->moduleDirectory);
// Repository...
$this->makeDirectory($this->moduleDirectory.'Repositories');
$this->makeRepository($this->moduleDirectory.'Repositories');
if ($this->option('plain')) {
return;
}
// Models...
$this->makeDirectory($this->moduleDirectory.'Models');
$this->makeModelFile($this->moduleDirectory.'Models');
// Database...
$this->makeDirectory($this->moduleDirectory.'Database');
$this->makeDirectory($this->moduleDirectory.'Database/Migrations');
$this->makeMigrationFile($this->moduleDirectory.'Database/Migrations');
// Controller...
$this->makeDirectory($this->moduleDirectory.'Controllers');
$this->makeController($this->moduleDirectory.'Controllers');
// Filament resource...
// $this->makeDirectory($this->moduleDirectory.'Filament');
// $this->makeDirectory($this->moduleDirectory.'Filament/Resources');
// $this->makeFilamentResource($this->moduleDirectory.'Filament/Resources');
}
/**
* Make module file
*/
public function makeModuleFile(string $moduleDirectory): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%sModule', $moduleDirectory, $this->moduleName),
stubFile: __DIR__.'/stubs/make-module/module.stub',
stubVariables: [
'NAMESPACE' => sprintf('App\\Modules\\%s', $this->moduleName),
'CLASS_NAME' => $this->moduleName.'Module',
]
);
$creationStatus
? $this->info("Module created: {$this->moduleName} created")
: $this->info("Module: {$this->moduleName} already exits");
}
/**
* Make model file
*/
protected function makeModelFile(string $modelPath): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%s', $modelPath, $this->moduleName),
stubFile: __DIR__.'/stubs/make-module/model.stub',
stubVariables: [
'NAMESPACE' => sprintf('App\\Modules\\%s\\Models', $this->moduleName),
'CLASS_NAME' => $this->moduleName,
]
);
$creationStatus
? $this->info("Model created: {$this->moduleName} created")
: $this->info("Model: {$this->moduleName} already exits");
}
/**
* Make migration file
*/
protected function makeMigrationFile(string $migrationsPath): void
{
$migrationCreator = new MigrationCreator(
files: new Filesystem,
customStubPath: modules_path('Core/Commands/stubs/make-module/migration.stub')
);
$migrationPath = $migrationCreator->create(Str::lower('create_'.Str::snake(Str::plural($this->moduleName)).'_table'), $migrationsPath);
$migrationName = Str::afterLast($migrationPath, '/');
$this->info("Migration created: {$migrationName} created");
}
/**
* Make controller file
*/
protected function makeController(string $controllersPath): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%sController', $controllersPath, $this->moduleName),
stubFile: modules_path('Core/Commands/stubs/make-module/controller.stub'),
stubVariables: [
'NAMESPACE' => sprintf('App\\Modules\\%s\\Controllers', $this->moduleName),
'CONTROLLER_NAME' => $this->moduleName.'Controller',
]
);
$creationStatus
? $this->info("Controller created: {$this->moduleName} created")
: $this->info("Controller: {$this->moduleName} already exits");
}
/**
* Make repository file
*/
protected function makeRepository(string $path): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%s', $path, $this->moduleName.'Repository'),
stubFile: __DIR__.'/stubs/make-module/repository.stub',
stubVariables: [
'NAMESPACE' => sprintf('App\Modules\%s\Repositories', $this->moduleName),
'MODULE_NAME' => ucfirst($this->moduleName),
'MODEL_NAMESPACE' => sprintf('App\Modules\%s\Models\%s', $this->moduleName, $this->moduleName),
],
);
$creationStatus
? $this->info("Repository created: {$this->moduleName} created")
: $this->info("Repository: {$this->moduleName} already exits");
}
/**
* Make nova resource file
*/
public function makeFilamentResource(string $path): void
{
// Base resource...
$resourceCreateStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%s', $path, $this->moduleName.'Resource'),
stubFile: __DIR__.'/stubs/make-module/filament/base-resource.stub',
stubVariables: [
'NAMESPACE' => sprintf('App\Modules\%s\Filament\Resources', $this->moduleName),
'MODEL_NAMESPACE' => sprintf('App\Modules\%s\Models\%s', $this->moduleName, $this->moduleName),
'MODEL_NAME_SINGULAR' => Str::of($this->moduleName)->singular(),
'MODEL_NAME_PLURAL' => Str::of($this->moduleName)->plural(),
],
);
$resourceCreateStatus
? $this->info("Filament resource created: {$this->moduleName} created")
: $this->info("Filament resource: {$this->moduleName} already exits");
$resourcePagesDir = $this->makeDirectory(sprintf('%s/%sResource', $path, $this->moduleName));
// Create page...
$resourceCreatePageStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/Create%s', $resourcePagesDir, $this->moduleName),
stubFile: __DIR__.'/stubs/make-module/filament/pages/create-resource-page.stub',
stubVariables: [
'CREATE_RESOURCE_PAGE_NAMESPACE' => sprintf('App\Modules\%s\Filament\Resources\%sResource\Pages', $this->moduleName, $this->moduleName),
'BASE_RESOURCE_NAMESPACE' => sprintf('App\Modules\%s\Filament\Resources\%sResource', $this->moduleName, $this->moduleName),
'MODEL_NAME_SINGULAR' => Str::of($this->moduleName)->singular(),
],
);
$resourceCreatePageStatus
? $this->info("Filament create page resource created: {$this->moduleName} created")
: $this->info("Filament create page resource: {$this->moduleName} already exits");
// Edit page...
$resourceEditPageStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/Edit%s', $resourcePagesDir, $this->moduleName),
stubFile: __DIR__.'/stubs/make-module/filament/pages/edit-resource-page.stub',
stubVariables: [
'EDIT_RESOURCE_PAGE_NAMESPACE' => sprintf('App\Modules\%s\Filament\Resources\%sResource\Pages', $this->moduleName, $this->moduleName),
'BASE_RESOURCE_NAMESPACE' => sprintf('App\Modules\%s\Filament\Resources\%sResource', $this->moduleName, $this->moduleName),
'MODEL_NAME_SINGULAR' => Str::of($this->moduleName)->singular(),
],
);
$resourceEditPageStatus
? $this->info("Filament edit page resource created: {$this->moduleName} created")
: $this->info("Filament edit page resource: {$this->moduleName} already exits");
// List page...
$resourceListPageStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/List%s', $resourcePagesDir, Str::of($this->moduleName)->plural()),
stubFile: __DIR__.'/stubs/make-module/filament/pages/list-resource-page.stub',
stubVariables: [
'LIST_RESOURCE_PAGE_NAMESPACE' => sprintf('App\Modules\%s\Filament\Resources\%sResource\Pages', $this->moduleName, $this->moduleName),
'BASE_RESOURCE_NAMESPACE' => sprintf('App\Modules\%s\Filament\Resources\%sResource', $this->moduleName, $this->moduleName),
'MODEL_NAME_SINGULAR' => Str::of($this->moduleName)->singular(),
'MODEL_NAME_PLURAL' => Str::of($this->moduleName)->plural(),
],
);
$resourceListPageStatus
? $this->info("Filament list page resource created: {$this->moduleName} created")
: $this->info("Filament list page resource: {$this->moduleName} already exits");
}
/**
* Build the directory for the class if necessary.
*/
protected function makeDirectory(string $path): string
{
if (! $this->files->isDirectory($path)) {
$this->files->makeDirectory($path, 0777, true, true);
}
return $path;
}
/**
* Create a file from stub
*
* @param array<string, string> $stubVariables
*/
protected function createFileFromStub(string $createFilePath, string $stubFile, array $stubVariables): int|bool
{
$contents = $this->getStubContents($stubFile, $stubVariables);
return $this->files->missing($createFilePath)
? $this->files->put($createFilePath.'.php', $contents)
: false;
}
/**
* Replace the stub variables(key) with the desire value
*
* @param array<string, string> $stubVariables
*/
protected function getStubContents(string $stub, array $stubVariables = []): string
{
$contents = (string) file_get_contents($stub);
foreach ($stubVariables as $search => $replace) {
$contents = str_replace('$'.$search.'$', $replace, $contents);
}
return $contents;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Modules\Core\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class ModuleMakeController extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:controller {module} {controller}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new controller for a module';
/**
* Execute the console command.
*/
public function handle(): void
{
$moduleName = $this->argument('module');
$controllerName = $this->argument('controller');
$modulePath = modules_path($moduleName);
if (! is_dir($modulePath)) {
$this->error("Module [{$moduleName}] does not exist.");
return;
}
$controllerPath = "App\\Modules\\{$moduleName}\\Controllers\\{$controllerName}";
Artisan::call('make:controller', [
'name' => $controllerPath,
]);
$this->info("Controller [{$controllerName}] created successfully in module [{$moduleName}].");
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Modules\Core\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class ModuleMakeMigration extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:migration {module} {migration}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new migration file for a module';
/**
* Execute the console command.
*/
public function handle(): void
{
$moduleName = $this->argument('module');
$migrationName = $this->argument('migration');
$modulePath = modules_path($moduleName);
if (! is_dir($modulePath)) {
$this->error("Module [{$moduleName}] does not exist.");
return;
}
$migrationPath = "app/Modules/{$moduleName}/Database/Migrations";
Artisan::call('make:migration', [
'name' => $migrationName,
'--path' => $migrationPath,
]);
$this->info("Migration [{$migrationName}] created successfully in module [{$moduleName}].");
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Modules\Core\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class ModuleMakeModel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:model {module} {model}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new model for a module';
/**
* Execute the console command.
*/
public function handle(): void
{
$moduleName = $this->argument('module');
$modelName = $this->argument('model');
$modulePath = modules_path($moduleName);
if (! is_dir($modulePath)) {
$this->error("Module [{$moduleName}] does not exist.");
return;
}
$modelPath = "App\\Modules\\{$moduleName}\\Models\\{$modelName}";
Artisan::call('make:model', [
'name' => $modelPath,
]);
$this->info("Model [{$modelName}] created successfully in module [{$moduleName}].");
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace $NAMESPACE$;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class $CONTROLLER_NAME$ extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request): void
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): void
{
//
}
/**
* Display the specified resource.
*/
public function show(Request $request): void
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request): void
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request): void
{
//
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace $NAMESPACE$;
use App\Modules\$MODEL_NAME_SINGULAR$\Filament\Resources\$MODEL_NAME_SINGULAR$Resource\Pages\Create$MODEL_NAME_SINGULAR$;
use App\Modules\$MODEL_NAME_SINGULAR$\Filament\Resources\$MODEL_NAME_SINGULAR$Resource\Pages\Edit$MODEL_NAME_SINGULAR$;
use App\Modules\$MODEL_NAME_SINGULAR$\Filament\Resources\$MODEL_NAME_SINGULAR$Resource\Pages\List$MODEL_NAME_SINGULAR$s;
use $MODEL_NAMESPACE$;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class $MODEL_NAME_SINGULAR$Resource extends Resource
{
protected static ?string $model = $MODEL_NAME_SINGULAR$::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
public static function form(Form $form): Form
{
return $form
->schema([
// ...
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => List$MODEL_NAME_PLURAL$::route('/'),
'create' => Create$MODEL_NAME_SINGULAR$::route('/create'),
'edit' => Edit$MODEL_NAME_SINGULAR$::route('/{record}/edit'),
];
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace $CREATE_RESOURCE_PAGE_NAMESPACE$;
use $BASE_RESOURCE_NAMESPACE$;
use Filament\Resources\Pages\CreateRecord;
class Create$MODEL_NAME_SINGULAR$ extends CreateRecord
{
protected static string $resource = $MODEL_NAME_SINGULAR$Resource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace $EDIT_RESOURCE_PAGE_NAMESPACE$;
use $BASE_RESOURCE_NAMESPACE$;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class Edit$MODEL_NAME_SINGULAR$ extends EditRecord
{
protected static string $resource = $MODEL_NAME_SINGULAR$Resource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace $LIST_RESOURCE_PAGE_NAMESPACE$;
use $BASE_RESOURCE_NAMESPACE$;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class List$MODEL_NAME_PLURAL$ extends ListRecords
{
protected static string $resource = $MODEL_NAME_SINGULAR$Resource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('{{ table }}', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('{{ table }}');
}
};

View File

@@ -0,0 +1,11 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
class $CLASS_NAME$ extends Model
{
}

View File

@@ -0,0 +1,64 @@
<?php
namespace $NAMESPACE$;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class $CLASS_NAME$ implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace $NAMESPACE$;
use App\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
/**
* @template TModel of \$MODEL_NAMESPACE$
*
* @extends Resource<TModel>
*/
class $RESOURCE_NAME_SINGULAR$ extends Resource
{
/**
* The model the resource corresponds to.
*
* @var class-string<\$MODEL_NAMESPACE$>
*/
public static $model = \$MODEL_NAMESPACE$::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array<int, string>
*/
public static $search = [
'id',
];
/**
* The relationships that should be eager loaded on index queries.
*
* @var array<int, string>
*/
// public static $with = [];
/**
* Get the displayable label of the resource.
*/
public static function label(): string
{
return __('$MODEL_NAME_PLURAL$');
}
/**
* Get the displayable singular label of the resource.
*/
public static function singularLabel(): string
{
return __('$MODEL_NAME_SINGULAR$');
}
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array<int, \Laravel\Nova\Fields\FieldElement|\Laravel\Nova\Panel>
*/
public function fields(NovaRequest $request): array
{
return [
ID::make('id')->sortable(),
];
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace $NAMESPACE$;
use $MODEL_NAMESPACE$;
class $MODULE_NAME$Repository
{
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Modules\Core;
class ModulePackage
{
public function __construct(
public ModulePackageType $type,
public string $name,
public string $message,
public string $version = '',
) {}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace App\Modules\Core;
enum ModulePackageType: string
{
case PACKAGE = 'package';
case MODULE = 'module';
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Modules\Country;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class CountryModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,256 @@
<?php
namespace App\Modules\Country\Repositories;
class CountryRepository
{
/**
* List of countries
*
* @return array<string, string>
*/
public static function values(): array
{
return [
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
'AQ' => 'Antarctica',
'AG' => 'Antigua and Barbuda',
'AR' => 'Argentina',
'AM' => 'Armenia',
'AW' => 'Aruba',
'AU' => 'Australia',
'AT' => 'Austria',
'AZ' => 'Azerbaijan',
'BS' => 'Bahamas',
'BH' => 'Bahrain',
'BD' => 'Bangladesh',
'BB' => 'Barbados',
'BY' => 'Belarus',
'BE' => 'Belgium',
'BZ' => 'Belize',
'BJ' => 'Benin',
'BM' => 'Bermuda',
'BT' => 'Bhutan',
'BO' => 'Bolivia',
'BA' => 'Bosnia and Herzegovina',
'BW' => 'Botswana',
'BV' => 'Bouvet Island',
'BR' => 'Brazil',
'IO' => 'British Indian Ocean Territory',
'BN' => 'Brunei Darussalam',
'BG' => 'Bulgaria',
'BF' => 'Burkina Faso',
'BI' => 'Burundi',
'KH' => 'Cambodia',
'CM' => 'Cameroon',
'CA' => 'Canada',
'CV' => 'Cape Verde',
'KY' => 'Cayman Islands',
'CF' => 'Central African Republic',
'TD' => 'Chad',
'CL' => 'Chile',
'CN' => 'China',
'CX' => 'Christmas Island',
'CC' => 'Cocos (Keeling) Islands',
'CO' => 'Colombia',
'KM' => 'Comoros',
'CG' => 'Congo',
'CD' => 'Congo, the Democratic Republic of the',
'CK' => 'Cook Islands',
'CR' => 'Costa Rica',
'CI' => "Cote D'Ivoire",
'HR' => 'Croatia',
'CU' => 'Cuba',
'CY' => 'Cyprus',
'CZ' => 'Czech Republic',
'DK' => 'Denmark',
'DJ' => 'Djibouti',
'DM' => 'Dominica',
'DO' => 'Dominican Republic',
'EC' => 'Ecuador',
'EG' => 'Egypt',
'SV' => 'El Salvador',
'GQ' => 'Equatorial Guinea',
'ER' => 'Eritrea',
'EE' => 'Estonia',
'ET' => 'Ethiopia',
'FK' => 'Falkland Islands (Malvinas)',
'FO' => 'Faroe Islands',
'FJ' => 'Fiji',
'FI' => 'Finland',
'FR' => 'France',
'GF' => 'French Guiana',
'PF' => 'French Polynesia',
'TF' => 'French Southern Territories',
'GA' => 'Gabon',
'GM' => 'Gambia',
'GE' => 'Georgia',
'DE' => 'Germany',
'GH' => 'Ghana',
'GI' => 'Gibraltar',
'GR' => 'Greece',
'GL' => 'Greenland',
'GD' => 'Grenada',
'GP' => 'Guadeloupe',
'GU' => 'Guam',
'GT' => 'Guatemala',
'GN' => 'Guinea',
'GW' => 'Guinea-Bissau',
'GY' => 'Guyana',
'HT' => 'Haiti',
'HM' => 'Heard Island and Mcdonald Islands',
'VA' => 'Holy See (Vatican City State)',
'HN' => 'Honduras',
'HK' => 'Hong Kong',
'HU' => 'Hungary',
'IS' => 'Iceland',
'IN' => 'India',
'ID' => 'Indonesia',
'IR' => 'Iran, Islamic Republic of',
'IQ' => 'Iraq',
'IE' => 'Ireland',
'IL' => 'Israel',
'IT' => 'Italy',
'JM' => 'Jamaica',
'JP' => 'Japan',
'JO' => 'Jordan',
'KZ' => 'Kazakhstan',
'KE' => 'Kenya',
'KI' => 'Kiribati',
'KP' => "Korea, Democratic People's Republic of",
'KR' => 'Korea, Republic of',
'KW' => 'Kuwait',
'KG' => 'Kyrgyzstan',
'LA' => "Lao People's Democratic Republic",
'LV' => 'Latvia',
'LB' => 'Lebanon',
'LS' => 'Lesotho',
'LR' => 'Liberia',
'LY' => 'Libyan Arab Jamahiriya',
'LI' => 'Liechtenstein',
'LT' => 'Lithuania',
'LU' => 'Luxembourg',
'MO' => 'Macao',
'MK' => 'Macedonia, the Former Yugoslav Republic of',
'MG' => 'Madagascar',
'MW' => 'Malawi',
'MY' => 'Malaysia',
'MV' => 'Maldives',
'ML' => 'Mali',
'MT' => 'Malta',
'MH' => 'Marshall Islands',
'MQ' => 'Martinique',
'MR' => 'Mauritania',
'MU' => 'Mauritius',
'YT' => 'Mayotte',
'MX' => 'Mexico',
'FM' => 'Micronesia, Federated States of',
'MD' => 'Moldova, Republic of',
'MC' => 'Monaco',
'MN' => 'Mongolia',
'MS' => 'Montserrat',
'MA' => 'Morocco',
'MZ' => 'Mozambique',
'MM' => 'Myanmar',
'NA' => 'Namibia',
'NR' => 'Nauru',
'NP' => 'Nepal',
'NL' => 'Netherlands',
'AN' => 'Netherlands Antilles',
'NC' => 'New Caledonia',
'NZ' => 'New Zealand',
'NI' => 'Nicaragua',
'NE' => 'Niger',
'NG' => 'Nigeria',
'NU' => 'Niue',
'NF' => 'Norfolk Island',
'MP' => 'Northern Mariana Islands',
'NO' => 'Norway',
'OM' => 'Oman',
'PK' => 'Pakistan',
'PW' => 'Palau',
'PS' => 'Palestinian Territory, Occupied',
'PA' => 'Panama',
'PG' => 'Papua New Guinea',
'PY' => 'Paraguay',
'PE' => 'Peru',
'PH' => 'Philippines',
'PN' => 'Pitcairn',
'PL' => 'Poland',
'PT' => 'Portugal',
'PR' => 'Puerto Rico',
'QA' => 'Qatar',
'RE' => 'Reunion',
'RO' => 'Romania',
'RU' => 'Russian Federation',
'RW' => 'Rwanda',
'SH' => 'Saint Helena',
'KN' => 'Saint Kitts and Nevis',
'LC' => 'Saint Lucia',
'PM' => 'Saint Pierre and Miquelon',
'VC' => 'Saint Vincent and the Grenadines',
'WS' => 'Samoa',
'SM' => 'San Marino',
'ST' => 'Sao Tome and Principe',
'SA' => 'Saudi Arabia',
'SN' => 'Senegal',
'CS' => 'Serbia and Montenegro',
'SC' => 'Seychelles',
'SL' => 'Sierra Leone',
'SG' => 'Singapore',
'SK' => 'Slovakia',
'SI' => 'Slovenia',
'SB' => 'Solomon Islands',
'SO' => 'Somalia',
'ZA' => 'South Africa',
'GS' => 'South Georgia and the South Sandwich Islands',
'ES' => 'Spain',
'LK' => 'Sri Lanka',
'SD' => 'Sudan',
'SR' => 'Suriname',
'SJ' => 'Svalbard and Jan Mayen',
'SZ' => 'Swaziland',
'SE' => 'Sweden',
'CH' => 'Switzerland',
'SY' => 'Syrian Arab Republic',
'TW' => 'Taiwan, Province of China',
'TJ' => 'Tajikistan',
'TZ' => 'Tanzania, United Republic of',
'TH' => 'Thailand',
'TL' => 'Timor-Leste',
'TG' => 'Togo',
'TK' => 'Tokelau',
'TO' => 'Tonga',
'TT' => 'Trinidad and Tobago',
'TN' => 'Tunisia',
'TR' => 'Turkey',
'TM' => 'Turkmenistan',
'TC' => 'Turks and Caicos Islands',
'TV' => 'Tuvalu',
'UG' => 'Uganda',
'UA' => 'Ukraine',
'AE' => 'United Arab Emirates',
'GB' => 'United Kingdom',
'US' => 'United States',
'UM' => 'United States Minor Outlying Islands',
'UY' => 'Uruguay',
'UZ' => 'Uzbekistan',
'VU' => 'Vanuatu',
'VE' => 'Venezuela',
'VN' => 'Viet Nam',
'VG' => 'Virgin Islands, British',
'VI' => 'Virgin Islands, U.s.',
'WF' => 'Wallis and Futuna',
'EH' => 'Western Sahara',
'YE' => 'Yemen',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe',
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Modules;
class EmptyModule implements ModuleContract
{
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return false;
}
/**
* Disable module
*/
public function disable(): void {}
/**
* Enable module
*/
public function enable(): void {}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Modules\IpStack;
use App\Modules\Core\ModulePackage;
use App\Modules\Core\ModulePackageType;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class IpStackModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [
new ModulePackage(
type: ModulePackageType::PACKAGE,
name: 'stevebauman/location',
message: 'Required for IP-based geolocation services.',
),
];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Modules\IpStack\Repositories;
use Stevebauman\Location\Facades\Location;
class IpStackRepository
{
/**
* Get ip stack
*/
public static function isLocalIp(string $ip): bool
{
return ! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
}
/**
* Get country code from ip
*/
public static function getCountryCodeFromIp(?string $ip): string
{
if (is_null($ip)) {
return 'TM';
}
return self::isLocalIp($ip) ? 'TM' : Location::get($ip)->countryCode ?? 'TM';
}
}

View File

@@ -0,0 +1,19 @@
<?php
use App\Modules\IpStack\Repositories\IpStackRepository;
/**
* Check if a client IP is in our Server subnet
*/
function isLocalIp(string $ip = ''): bool
{
return IpStackRepository::isLocalIp($ip);
}
/**
* Get country code from ip
*/
function getCountryCodeFromIp(?string $ip = ''): string
{
return IpStackRepository::getCountryCodeFromIp($ip);
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Modules\Loan\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class LoanController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request): void
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): void
{
//
}
/**
* Display the specified resource.
*/
public function show(Request $request): void
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request): void
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request): void
{
//
}
}

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('loans', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->string('passport_serie')->index();
$table->string('passport_id')->index();
$table->string('account_number')->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('loans');
}
};

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Modules\Loan;
use App\Modules\Makeable;
use App\Modules\ModuleContract;
class LoanModule implements ModuleContract
{
use Makeable;
/**
* Module is enabled
*/
protected bool $enabled = true;
/**
* Check if is module enabled
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Disable module
*/
public function disable(): void
{
$this->enabled = false;
}
/**
* Enable module
*/
public function enable(): void
{
$this->enabled = true;
}
/**
* Check if module has a filament resource
*/
public function hasFilamentResource(): bool
{
return false;
}
/**
* Get module composer requirements
*/
public function getComposerRequirements(): array
{
return [];
}
/**
* Get module composer suggestions
*/
public function getComposerSuggestions(): array
{
return [];
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Modules\Loan\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Date;
/**
* @property int $id
* @property int $user_id
* @property int $passport_serie
* @property int $passport_id
* @property int $ account_number
* @property Date|null $created_at
* @property Date|null $updated_at
*/
class Loan extends Model
{
/** @var string */
protected $table = 'loans';
/**
* User
*
* @return BelongsTo<User::class>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace App\Modules\Loan\Repositories;
class LoanRepository {}

Some files were not shown because too many files have changed in this diff Show More