install
This commit is contained in:
64
app/Modules/AppHelpers/AppHelpersModule.php
Normal file
64
app/Modules/AppHelpers/AppHelpersModule.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
67
app/Modules/AppHelpers/Repositories/CacheRepository.php
Normal file
67
app/Modules/AppHelpers/Repositories/CacheRepository.php
Normal 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);
|
||||
}
|
||||
}
|
||||
78
app/Modules/BaseAuth/BaseAuthModule.php
Normal file
78
app/Modules/BaseAuth/BaseAuthModule.php
Normal 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.',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Modules/BaseAuth/Configs/base-auth-config.php
Normal file
22
app/Modules/BaseAuth/Configs/base-auth-config.php
Normal 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,
|
||||
];
|
||||
184
app/Modules/BaseAuth/Controllers/LoginController.php
Normal file
184
app/Modules/BaseAuth/Controllers/LoginController.php
Normal 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
|
||||
}
|
||||
}
|
||||
173
app/Modules/BaseAuth/Controllers/RegisterController.php
Normal file
173
app/Modules/BaseAuth/Controllers/RegisterController.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
110
app/Modules/BaseAuth/Controllers/ResetPasswordController.php
Normal file
110
app/Modules/BaseAuth/Controllers/ResetPasswordController.php
Normal 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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
111
app/Modules/BaseAuth/Models/AuthEvent.php
Normal file
111
app/Modules/BaseAuth/Models/AuthEvent.php
Normal 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',
|
||||
};
|
||||
}
|
||||
}
|
||||
16
app/Modules/BaseAuth/Resources/Lang/en/base.php
Normal file
16
app/Modules/BaseAuth/Resources/Lang/en/base.php
Normal 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',
|
||||
];
|
||||
5
app/Modules/BaseAuth/Resources/Lang/ru/base.php
Normal file
5
app/Modules/BaseAuth/Resources/Lang/ru/base.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
];
|
||||
32
app/Modules/BaseAuth/Resources/Lang/tk/base.php
Normal file
32
app/Modules/BaseAuth/Resources/Lang/tk/base.php
Normal 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',
|
||||
];
|
||||
@@ -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>
|
||||
|
||||
88
app/Modules/BaseAuth/Resources/Views/pages/login.blade.php
Normal file
88
app/Modules/BaseAuth/Resources/Views/pages/login.blade.php
Normal 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
|
||||
124
app/Modules/BaseAuth/Resources/Views/pages/register.blade.php
Normal file
124
app/Modules/BaseAuth/Resources/Views/pages/register.blade.php
Normal 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
|
||||
@@ -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
|
||||
@@ -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>
|
||||
28
app/Modules/BaseAuth/Routes/base-auth-routes.php
Normal file
28
app/Modules/BaseAuth/Routes/base-auth-routes.php
Normal 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']);
|
||||
|
||||
});
|
||||
48
app/Modules/BaseAuth/base-auth-helpers.php
Normal file
48
app/Modules/BaseAuth/base-auth-helpers.php
Normal 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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
64
app/Modules/BaseLocale/BaseLocaleModule.php
Normal file
64
app/Modules/BaseLocale/BaseLocaleModule.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
9
app/Modules/BaseLocale/Configs/base-locale-config.php
Normal file
9
app/Modules/BaseLocale/Configs/base-locale-config.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'locales' => [
|
||||
'tk' => 'Türkmen',
|
||||
'en' => 'English',
|
||||
'ru' => 'Русский',
|
||||
],
|
||||
];
|
||||
21
app/Modules/BaseLocale/Controllers/BaseLocaleController.php
Normal file
21
app/Modules/BaseLocale/Controllers/BaseLocaleController.php
Normal 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();
|
||||
}
|
||||
}
|
||||
35
app/Modules/BaseLocale/Middleware/SetLocale.php
Normal file
35
app/Modules/BaseLocale/Middleware/SetLocale.php
Normal 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);
|
||||
}
|
||||
}
|
||||
8
app/Modules/BaseLocale/Routes/base-locale-routes.php
Normal file
8
app/Modules/BaseLocale/Routes/base-locale-routes.php
Normal 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');
|
||||
});
|
||||
35
app/Modules/BaseLocale/base-locale-helpers.php
Normal file
35
app/Modules/BaseLocale/base-locale-helpers.php
Normal 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);
|
||||
}
|
||||
}
|
||||
15
app/Modules/BaseModule.php
Normal file
15
app/Modules/BaseModule.php
Normal 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();
|
||||
}
|
||||
}
|
||||
64
app/Modules/Branch/BranchModule.php
Normal file
64
app/Modules/Branch/BranchModule.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
38
app/Modules/Branch/Controllers/BranchController.php
Normal file
38
app/Modules/Branch/Controllers/BranchController.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
11
app/Modules/Branch/Interfaces/BelongsToBranch.php
Normal file
11
app/Modules/Branch/Interfaces/BelongsToBranch.php
Normal 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 {}
|
||||
80
app/Modules/Branch/Models/Branch.php
Normal file
80
app/Modules/Branch/Models/Branch.php
Normal 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);
|
||||
}
|
||||
}
|
||||
5
app/Modules/Branch/Repositories/BranchRepository.php
Normal file
5
app/Modules/Branch/Repositories/BranchRepository.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Branch\Repositories;
|
||||
|
||||
class BranchRepository {}
|
||||
6
app/Modules/Branch/Resources/Lang/tk/base.php
Normal file
6
app/Modules/Branch/Resources/Lang/tk/base.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'branch' => 'Şahamça',
|
||||
'branches' => 'Şahamçalar',
|
||||
];
|
||||
313
app/Modules/Core/Commands/MakeModule.php
Normal file
313
app/Modules/Core/Commands/MakeModule.php
Normal 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;
|
||||
}
|
||||
}
|
||||
47
app/Modules/Core/Commands/ModuleMakeController.php
Normal file
47
app/Modules/Core/Commands/ModuleMakeController.php
Normal 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}].");
|
||||
}
|
||||
}
|
||||
48
app/Modules/Core/Commands/ModuleMakeMigration.php
Normal file
48
app/Modules/Core/Commands/ModuleMakeMigration.php
Normal 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}].");
|
||||
}
|
||||
}
|
||||
47
app/Modules/Core/Commands/ModuleMakeModel.php
Normal file
47
app/Modules/Core/Commands/ModuleMakeModel.php
Normal 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}].");
|
||||
}
|
||||
}
|
||||
49
app/Modules/Core/Commands/stubs/make-module/controller.stub
Normal file
49
app/Modules/Core/Commands/stubs/make-module/controller.stub
Normal 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
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Modules/Core/Commands/stubs/make-module/migration.stub
Executable file
27
app/Modules/Core/Commands/stubs/make-module/migration.stub
Executable 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 }}');
|
||||
}
|
||||
};
|
||||
11
app/Modules/Core/Commands/stubs/make-module/model.stub
Normal file
11
app/Modules/Core/Commands/stubs/make-module/model.stub
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class $CLASS_NAME$ extends Model
|
||||
{
|
||||
|
||||
}
|
||||
64
app/Modules/Core/Commands/stubs/make-module/module.stub
Normal file
64
app/Modules/Core/Commands/stubs/make-module/module.stub
Normal 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 [];
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
10
app/Modules/Core/Commands/stubs/make-module/repository.stub
Normal file
10
app/Modules/Core/Commands/stubs/make-module/repository.stub
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use $MODEL_NAMESPACE$;
|
||||
|
||||
class $MODULE_NAME$Repository
|
||||
{
|
||||
|
||||
}
|
||||
13
app/Modules/Core/ModulePackage.php
Normal file
13
app/Modules/Core/ModulePackage.php
Normal 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 = '',
|
||||
) {}
|
||||
}
|
||||
9
app/Modules/Core/ModulePackageType.php
Normal file
9
app/Modules/Core/ModulePackageType.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Core;
|
||||
|
||||
enum ModulePackageType: string
|
||||
{
|
||||
case PACKAGE = 'package';
|
||||
case MODULE = 'module';
|
||||
}
|
||||
64
app/Modules/Country/CountryModule.php
Normal file
64
app/Modules/Country/CountryModule.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
256
app/Modules/Country/Repositories/CountryRepository.php
Normal file
256
app/Modules/Country/Repositories/CountryRepository.php
Normal 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',
|
||||
];
|
||||
}
|
||||
}
|
||||
48
app/Modules/EmptyModule.php
Normal file
48
app/Modules/EmptyModule.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
72
app/Modules/IpStack/IpStackModule.php
Normal file
72
app/Modules/IpStack/IpStackModule.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
28
app/Modules/IpStack/Repositories/IpStackRepository.php
Normal file
28
app/Modules/IpStack/Repositories/IpStackRepository.php
Normal 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';
|
||||
}
|
||||
}
|
||||
19
app/Modules/IpStack/ip-stack-helpers.php
Normal file
19
app/Modules/IpStack/ip-stack-helpers.php
Normal 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);
|
||||
}
|
||||
49
app/Modules/Loan/Controllers/LoanController.php
Normal file
49
app/Modules/Loan/Controllers/LoanController.php
Normal 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
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
64
app/Modules/Loan/LoanModule.php
Normal file
64
app/Modules/Loan/LoanModule.php
Normal 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 [];
|
||||
}
|
||||
}
|
||||
33
app/Modules/Loan/Models/Loan.php
Normal file
33
app/Modules/Loan/Models/Loan.php
Normal 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);
|
||||
}
|
||||
}
|
||||
5
app/Modules/Loan/Repositories/LoanRepository.php
Normal file
5
app/Modules/Loan/Repositories/LoanRepository.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Loan\Repositories;
|
||||
|
||||
class LoanRepository {}
|
||||
49
app/Modules/LoanOrder/Controllers/LoanOrderController.php
Normal file
49
app/Modules/LoanOrder/Controllers/LoanOrderController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\LoanOrder\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LoanOrderController 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
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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('loan_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->json('name');
|
||||
$table->string('tax')->nullable();
|
||||
$table->string('maturity')->nullable();
|
||||
$table->string('notes')->nullable();
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('loan_types');
|
||||
}
|
||||
};
|
||||
@@ -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('loan_order_required_docs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->text('name');
|
||||
$table->text('value');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('loan_order_required_docs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,138 @@
|
||||
<?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('loan_orders', function (Blueprint $table) {
|
||||
// Unique ID
|
||||
$table->id();
|
||||
$table->string('unique_id')->nullable()->unique();
|
||||
|
||||
// web, app
|
||||
$table->string('source')->default('web')->index()->nullable();
|
||||
|
||||
// User
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
|
||||
// Loan Type
|
||||
$table->foreignId('loan_type')->constrained('loan_types')->restrictOnDelete();
|
||||
|
||||
// Region & Branch
|
||||
$table->string('region', 2);
|
||||
$table->foreignId('branch_id')->constrained('branches')->restrictOnDelete();
|
||||
|
||||
// Customer name,surname,patronic name
|
||||
$table->string('customer_name')->index();
|
||||
$table->string('customer_surname')->index();
|
||||
$table->string('customer_patronic_name')->nullable();
|
||||
|
||||
// Passport address, real address
|
||||
$table->string('passport_address');
|
||||
$table->string('real_address');
|
||||
|
||||
// Passport data
|
||||
$table->string('passport_serie')->index();
|
||||
$table->string('passport_id')->index();
|
||||
$table->date('passport_given_at');
|
||||
$table->string('passport_given_by');
|
||||
$table->string('born_place');
|
||||
$table->date('born_at');
|
||||
|
||||
// Email, phone, phone additional, phone home
|
||||
$table->string('email')->nullable();
|
||||
|
||||
$table->string('phone')->index();
|
||||
$table->string('phone_additional')->nullable();
|
||||
$table->string('phone_home')->nullable();
|
||||
|
||||
$table->string('work_region')->nullable()->index();
|
||||
$table->foreignId('work_province_id')->nullable()->constrained('provinces')->restrictOnDelete();
|
||||
|
||||
$table->string('work_company')->nullable();
|
||||
$table->string('work_company_accountant_number')->nullable();
|
||||
|
||||
$table->date('work_started_at')->nullable();
|
||||
$table->string('work_salary')->nullable();
|
||||
$table->string('work_position')->nullable();
|
||||
|
||||
$table->string('education')->index();
|
||||
$table->string('marriage_status')->index();
|
||||
|
||||
$table->text('passport_one');
|
||||
$table->text('passport_two');
|
||||
$table->text('passport_three');
|
||||
$table->text('passport_four');
|
||||
|
||||
$table->string('loan_amount')->nullable()->index();
|
||||
|
||||
$table->string('card_number')->nullable();
|
||||
$table->string('card_name')->nullable();
|
||||
$table->string('card_month')->nullable();
|
||||
$table->string('card_year')->nullable();
|
||||
|
||||
// Guarantor one begin
|
||||
$table->string('guarantor_name')->nullable();
|
||||
$table->string('guarantor_surname')->nullable();
|
||||
$table->string('guarantor_patronic_name')->nullable();
|
||||
$table->string('guarantor_passport_serie')->nullable();
|
||||
$table->string('guarantor_passport_id')->nullable();
|
||||
|
||||
$table->string('guarantor_card_number')->nullable();
|
||||
$table->string('guarantor_card_name')->nullable();
|
||||
$table->string('guarantor_card_month')->nullable();
|
||||
$table->string('guarantor_card_year')->nullable();
|
||||
|
||||
$table->string('guarantor_note')->nullable();
|
||||
// Guarantor one end
|
||||
|
||||
// Guarantor two begin
|
||||
$table->string('guarantor_2_name')->nullable();
|
||||
$table->string('guarantor_2_surname')->nullable();
|
||||
$table->string('guarantor_2_patronic_name')->nullable();
|
||||
|
||||
$table->string('guarantor_2_passport_serie')->nullable();
|
||||
$table->string('guarantor_2_passport_id')->nullable();
|
||||
|
||||
$table->string('guarantor_2_card_number')->nullable();
|
||||
$table->string('guarantor_2_card_name')->nullable();
|
||||
$table->string('guarantor_2_card_month')->nullable();
|
||||
$table->string('guarantor_2_card_year')->nullable();
|
||||
|
||||
$table->string('guarantor_2_note')->nullable();
|
||||
// Guarantor two end
|
||||
|
||||
// Loan card begin
|
||||
$table->string('loan_card_number')->nullable();
|
||||
$table->string('loan_card_name')->nullable();
|
||||
$table->string('loan_card_month')->nullable();
|
||||
$table->string('loan_card_year')->nullable();
|
||||
|
||||
$table->foreignId('loan_order_required_doc_id')->nullable()->constrained('loan_order_required_docs')->restrictOnDelete();
|
||||
// Loan card end
|
||||
|
||||
$table->string('status')->nullable();
|
||||
$table->string('satisfiable')->nullable();
|
||||
|
||||
$table->text('notes')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('loan_orders');
|
||||
}
|
||||
};
|
||||
72
app/Modules/LoanOrder/LoanOrderModule.php
Normal file
72
app/Modules/LoanOrder/LoanOrderModule.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\LoanOrder;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
use App\Modules\Core\ModulePackageType;
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class LoanOrderModule 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: 'spatie/laravel-translatable',
|
||||
message: 'Laravel Translatable is required to use this module.',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer suggestions
|
||||
*/
|
||||
public function getComposerSuggestions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
173
app/Modules/LoanOrder/Models/LoanOrder.php
Normal file
173
app/Modules/LoanOrder/Models/LoanOrder.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\LoanOrder\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Branch\Interfaces\BelongsToBranch;
|
||||
use App\Modules\Branch\Models\Branch;
|
||||
use App\Modules\LoanOrder\Repositories\LoanOrderRepository;
|
||||
use App\Modules\OrderStatus\Interfaces\HasStatus;
|
||||
use App\Modules\Province\Models\Province;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $unique_id
|
||||
* @property string|null $source
|
||||
* @property int|null $user_id
|
||||
* @property int $loan_type
|
||||
* @property string $region
|
||||
* @property int $branch_id
|
||||
* @property string $customer_name
|
||||
* @property string $customer_surname
|
||||
* @property string|null $customer_patronic_name
|
||||
* @property string $passport_address
|
||||
* @property string $real_address
|
||||
* @property string $passport_serie
|
||||
* @property string $passport_id
|
||||
* @property Carbon $passport_given_at
|
||||
* @property string $passport_given_by
|
||||
* @property string $born_place
|
||||
* @property Carbon $born_at
|
||||
* @property string|null $email
|
||||
* @property string $phone
|
||||
* @property string|null $phone_additional
|
||||
* @property string|null $phone_home
|
||||
* @property string|null $work_region
|
||||
* @property int|null $work_province_id
|
||||
* @property string|null $work_company
|
||||
* @property string|null $work_company_accountant_number
|
||||
* @property Carbon|null $work_started_at
|
||||
* @property string|null $work_salary
|
||||
* @property string|null $work_position
|
||||
* @property string $education
|
||||
* @property string $marriage_status
|
||||
* @property string $passport_one
|
||||
* @property string $passport_two
|
||||
* @property string $passport_three
|
||||
* @property string $passport_four
|
||||
* @property string|null $loan_amount
|
||||
* @property string|null $card_number
|
||||
* @property string|null $card_name
|
||||
* @property string|null $card_month
|
||||
* @property string|null $card_year
|
||||
* @property string $guarantor_name
|
||||
* @property string|null $guarantor_surname
|
||||
* @property string|null $guarantor_patronic_name
|
||||
* @property string|null $guarantor_passport_serie
|
||||
* @property string|null $guarantor_passport_id
|
||||
* @property string|null $guarantor_card_number
|
||||
* @property string|null $guarantor_card_name
|
||||
* @property string|null $guarantor_card_month
|
||||
* @property string|null $guarantor_card_year
|
||||
* @property string|null $guarantor_note
|
||||
* @property string|null $guarantor_2_name
|
||||
* @property string|null $guarantor_2_surname
|
||||
* @property string|null $guarantor_2_patronic_name
|
||||
* @property string|null $guarantor_2_passport_serie
|
||||
* @property string|null $guarantor_2_passport_id
|
||||
* @property string|null $guarantor_2_card_number
|
||||
* @property string|null $guarantor_2_card_name
|
||||
* @property string|null $guarantor_2_card_month
|
||||
* @property string|null $guarantor_2_card_year
|
||||
* @property string|null $guarantor_2_note
|
||||
* @property string|null $loan_card_number
|
||||
* @property string|null $loan_card_name
|
||||
* @property string|null $loan_card_month
|
||||
* @property string|null $loan_card_year
|
||||
* @property int $loan_order_required_doc_id
|
||||
* @property string|null $status
|
||||
* @property string|null $satisfiable
|
||||
* @property string|null $notes
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property Carbon|null $deleted_at
|
||||
*/
|
||||
class LoanOrder extends Model implements BelongsToBranch, HasStatus
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'passport_given_at' => 'date',
|
||||
'born_at' => 'date',
|
||||
'work_started_at' => 'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Loan type
|
||||
*
|
||||
* @return BelongsTo<LoanType, $this>
|
||||
*/
|
||||
public function loanType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(LoanType::class, 'loan_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Branch
|
||||
*
|
||||
* @return BelongsTo<Branch, $this>
|
||||
*/
|
||||
public function branch(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Branch::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Work province
|
||||
*
|
||||
* @return BelongsTo<Province, $this>
|
||||
*/
|
||||
public function workProvince(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Province::class, 'work_province_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* User (who created order)
|
||||
*
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Required docs
|
||||
*
|
||||
* @return BelongsTo<LoanOrderRequiredDocs, $this>
|
||||
*/
|
||||
public function requiredDocs(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(LoanOrderRequiredDocs::class, 'loan_order_required_doc_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* "boot" method for model
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(LoanOrderRepository::creating());
|
||||
static::created(LoanOrderRepository::created());
|
||||
// static::updated(function (LoanOrder $model) {
|
||||
// if ($model->notes && $model->wasChanged('notes')) {
|
||||
// Alert::create([
|
||||
// 'user_id' => $model->user_id,
|
||||
// 'name' => 'Duýdyryş',
|
||||
// 'value' => $model->notes,
|
||||
// ]);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
44
app/Modules/LoanOrder/Models/LoanOrderRequiredDocs.php
Normal file
44
app/Modules/LoanOrder/Models/LoanOrderRequiredDocs.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\LoanOrder\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $value
|
||||
* @property \Illuminate\Support\Carbon $created_at
|
||||
* @property \Illuminate\Support\Carbon $updated_at
|
||||
*/
|
||||
class LoanOrderRequiredDocs extends Model
|
||||
{
|
||||
use HasTranslations;
|
||||
|
||||
/**
|
||||
* Table
|
||||
*/
|
||||
protected $table = 'loan_order_required_docs';
|
||||
|
||||
/**
|
||||
* Translatable fields
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public $translatable = [
|
||||
'name',
|
||||
'value',
|
||||
];
|
||||
|
||||
/**
|
||||
* Loan orders
|
||||
*
|
||||
* @return HasMany<LoanOrder, $this>
|
||||
*/
|
||||
public function loanOrders(): HasMany
|
||||
{
|
||||
return $this->hasMany(LoanOrder::class, 'loan_order_required_doc_id');
|
||||
}
|
||||
}
|
||||
37
app/Modules/LoanOrder/Models/LoanType.php
Normal file
37
app/Modules/LoanOrder/Models/LoanType.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\LoanOrder\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property array<string, string> $name
|
||||
* @property string|null $tax
|
||||
* @property string|null $maturity
|
||||
* @property string|null $notes
|
||||
* @property bool $active
|
||||
* @property \Illuminate\Support\Carbon $created_at
|
||||
* @property \Illuminate\Support\Carbon $updated_at
|
||||
*/
|
||||
class LoanType extends Model
|
||||
{
|
||||
use HasTranslations;
|
||||
|
||||
/**
|
||||
* Translatable fields
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
public $translatable = ['name', 'notes'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'active' => 'boolean',
|
||||
];
|
||||
}
|
||||
59
app/Modules/LoanOrder/Repositories/LoanOrderRepository.php
Normal file
59
app/Modules/LoanOrder/Repositories/LoanOrderRepository.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\LoanOrder\Repositories;
|
||||
|
||||
use App\Modules\Branch\Interfaces\BelongsToBranch;
|
||||
use App\Modules\Branch\Models\Branch;
|
||||
use App\Modules\OrderStatus\Interfaces\HasStatus;
|
||||
use App\Modules\OrderStatus\Repositories\OrderStatusRepository;
|
||||
use Closure;
|
||||
|
||||
class LoanOrderRepository
|
||||
{
|
||||
/**
|
||||
* Satisfiable values
|
||||
*
|
||||
* @return array<string|null, string>
|
||||
*/
|
||||
public static function satisfiableValues(): array
|
||||
{
|
||||
return [
|
||||
null => '-',
|
||||
'satisfiable' => __('Satisfiable'),
|
||||
'insufficient' => __('Insufficient'),
|
||||
'unknown' => __('Unknown'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* When model is being created
|
||||
*/
|
||||
public static function creating(): Closure
|
||||
{
|
||||
return function (HasStatus $model) {
|
||||
$model->status = $model->status ?: OrderStatusRepository::defaultStatus();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* When model is created
|
||||
*/
|
||||
public static function created(): Closure
|
||||
{
|
||||
return function ($model) {
|
||||
$model->update(['unique_id' => static::generateUniqueId($model)]);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill unique id
|
||||
*/
|
||||
public static function generateUniqueId(BelongsToBranch $model): string
|
||||
{
|
||||
return sprintf(
|
||||
'TB%s-%s',
|
||||
Branch::find($model->branch_id)->unique_code ?? uniqid(),
|
||||
$model->id,
|
||||
);
|
||||
}
|
||||
}
|
||||
10
app/Modules/LoanOrder/Resources/Lang/tk/loan-order.php
Normal file
10
app/Modules/LoanOrder/Resources/Lang/tk/loan-order.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'loan' => 'Karz',
|
||||
'loans' => 'Karzlar',
|
||||
'loan_order' => 'Karz sargyt',
|
||||
'loan_orders' => 'Karz sargytlary',
|
||||
'loan_order_required_docs' => 'Karz gerekli resminamalar',
|
||||
'loan_order_required_docs_plural' => 'Karz gerekli resminamalar',
|
||||
];
|
||||
6
app/Modules/LoanOrder/Resources/Lang/tk/loan-type.php
Normal file
6
app/Modules/LoanOrder/Resources/Lang/tk/loan-type.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'loan_type' => 'Karz görnüşi',
|
||||
'loan_types' => 'Karz görnüşleri',
|
||||
];
|
||||
17
app/Modules/Makeable.php
Normal file
17
app/Modules/Makeable.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules;
|
||||
|
||||
trait Makeable
|
||||
{
|
||||
/**
|
||||
* Create a new element.
|
||||
*
|
||||
* @param mixed ...$arguments
|
||||
* @return static
|
||||
*/
|
||||
public static function make(...$arguments)
|
||||
{
|
||||
return new static(...$arguments);
|
||||
}
|
||||
}
|
||||
42
app/Modules/ModuleContract.php
Normal file
42
app/Modules/ModuleContract.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
|
||||
interface ModuleContract
|
||||
{
|
||||
/**
|
||||
* Check if is module enabled
|
||||
*/
|
||||
public function isEnabled(): bool;
|
||||
|
||||
/**
|
||||
* Disable module
|
||||
*/
|
||||
public function disable(): void;
|
||||
|
||||
/**
|
||||
* Enable module
|
||||
*/
|
||||
public function enable(): void;
|
||||
|
||||
/**
|
||||
* Check if module has a filament resource
|
||||
*/
|
||||
public function hasFilamentResource(): bool;
|
||||
|
||||
/**
|
||||
* Get module composer requirements
|
||||
*
|
||||
* @return array<int, ModulePackage>
|
||||
*/
|
||||
public function getComposerRequirements(): array;
|
||||
|
||||
/**
|
||||
* Get module composer suggestions
|
||||
*
|
||||
* @return array<int, ModulePackage>
|
||||
*/
|
||||
public function getComposerSuggestions(): array;
|
||||
}
|
||||
129
app/Modules/ModuleRepository.php
Normal file
129
app/Modules/ModuleRepository.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ModuleRepository
|
||||
{
|
||||
public function __construct(
|
||||
/** @var string */
|
||||
protected string $modules_path = '',
|
||||
|
||||
/** @var Collection<array-key, BaseModule> */
|
||||
protected Collection $modules = new Collection([]),
|
||||
|
||||
/** @var Collection<array-key, BaseModule> */
|
||||
protected Collection $allModules = new Collection([]),
|
||||
) {
|
||||
$this->prepareModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare modules
|
||||
*/
|
||||
public function prepareModules(): void
|
||||
{
|
||||
$this->setPath();
|
||||
$this->setModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set path
|
||||
*/
|
||||
public function setPath(): void
|
||||
{
|
||||
$this->modules_path = __DIR__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set modules
|
||||
*/
|
||||
public function setModules(bool $withDisabled = false): void
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
$modulesDir = File::directories($this->path());
|
||||
|
||||
foreach ($modulesDir as $modulePath) {
|
||||
if (Str::contains($modulePath, 'Core')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$moduleName = Str::afterLast($modulePath, '/');
|
||||
|
||||
$module = new BaseModule(
|
||||
path: $modulePath,
|
||||
name: $moduleName,
|
||||
app: $this->module($moduleName),
|
||||
);
|
||||
|
||||
$this->allModules->push($module);
|
||||
|
||||
// Include all
|
||||
if ($withDisabled) {
|
||||
$this->modules->push($module);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($module->app->isEnabled()) {
|
||||
$this->modules->push($module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modules path
|
||||
*/
|
||||
public function path(): string
|
||||
{
|
||||
return $this->modules_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate new module class if exists
|
||||
*/
|
||||
public function module(string $moduleName): ModuleContract
|
||||
{
|
||||
$moduleClass = 'App\\Modules\\'.$moduleName.'\\'.$moduleName.'Module';
|
||||
|
||||
if (class_exists($moduleClass)) {
|
||||
/** @var ModuleContract $module */
|
||||
$module = new $moduleClass;
|
||||
|
||||
return $module;
|
||||
}
|
||||
|
||||
return $this->emptyModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Modules
|
||||
*
|
||||
* @return Collection<array-key, BaseModule>
|
||||
*/
|
||||
public function modules(): Collection
|
||||
{
|
||||
return $this->modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty module
|
||||
*/
|
||||
public function emptyModule(): ModuleContract
|
||||
{
|
||||
return new EmptyModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all modules regardless if disabled
|
||||
*
|
||||
* @return Collection<array-key, BaseModule>
|
||||
*/
|
||||
public function allModules(): Collection
|
||||
{
|
||||
return $this->allModules;
|
||||
}
|
||||
}
|
||||
177
app/Modules/ModuleServiceProvider.php
Normal file
177
app/Modules/ModuleServiceProvider.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ModuleServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(ModuleRepository::class, function (Application $app) {
|
||||
return new ModuleRepository;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadModuleCommands();
|
||||
|
||||
modules()->each(function (BaseModule $module) {
|
||||
// Verify module composer requirements
|
||||
$this->verifyModuleComposerRequirements($module);
|
||||
|
||||
// Suggest module composer suggestions
|
||||
$this->suggestModuleComposerSuggestions($module);
|
||||
|
||||
// Module Routes
|
||||
$this->loadModuleRoutes($module);
|
||||
|
||||
// Module Migrations
|
||||
$this->loadModuleMigrations($module);
|
||||
|
||||
// Module Views
|
||||
$this->loadModuleViews($module);
|
||||
|
||||
// Module Helpers
|
||||
$this->loadModuleHelpers($module);
|
||||
|
||||
// Module Translations
|
||||
$this->loadModuleTranslations($module);
|
||||
|
||||
// Module Configs
|
||||
$this->loadModuleConfigs($module);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify module composer requirements
|
||||
*/
|
||||
public function verifyModuleComposerRequirements(BaseModule $module): void
|
||||
{
|
||||
// foreach ($module->app->getComposerRequirements() as $requirement) {
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Suggest module composer suggestions
|
||||
*/
|
||||
public function suggestModuleComposerSuggestions(BaseModule $module): void
|
||||
{
|
||||
// foreach ($module->app->getComposerSuggestions() as $suggestion) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module configs
|
||||
*/
|
||||
public function loadModuleConfigs(BaseModule $module): void
|
||||
{
|
||||
$moduleName = Str::kebab($module->name);
|
||||
|
||||
$configPath = sprintf('%s/Configs/%s-config.php', $module->path, $moduleName);
|
||||
|
||||
if (is_file($configPath)) {
|
||||
$this->mergeConfigFrom($configPath, 'module.'.$moduleName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module views
|
||||
*/
|
||||
public function loadModuleViews(BaseModule $module): void
|
||||
{
|
||||
$moduleName = Str::kebab($module->name);
|
||||
|
||||
$viewsPath = $module->path.'/Resources/Views';
|
||||
|
||||
if (is_dir($viewsPath)) {
|
||||
$this->loadViewsFrom($viewsPath, 'module.'.$moduleName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module migrations
|
||||
*/
|
||||
public function loadModuleMigrations(BaseModule $module): void
|
||||
{
|
||||
$migrationDirectory = $module->path.'/Database/Migrations';
|
||||
|
||||
if (is_dir($migrationDirectory)) {
|
||||
$this->loadMigrationsFrom($migrationDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module routes
|
||||
*/
|
||||
public function loadModuleRoutes(BaseModule $module): void
|
||||
{
|
||||
$routesPath = sprintf('%s/Routes/%s-routes.php', $module->path, Str::kebab($module->name));
|
||||
|
||||
if (is_file($routesPath)) {
|
||||
$this->loadRoutesFrom($routesPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module helpers
|
||||
*/
|
||||
public function loadModuleHelpers(BaseModule $module): void
|
||||
{
|
||||
$moduleName = Str::kebab($module->name);
|
||||
|
||||
$helpersPath = sprintf('%s/%s-helpers.php', $module->path, $moduleName);
|
||||
|
||||
if (is_file($helpersPath)) {
|
||||
require_once $helpersPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module translations
|
||||
*/
|
||||
public function loadModuleTranslations(BaseModule $module): void
|
||||
{
|
||||
$translationsPath = sprintf('%s/Resources/lang', $module->path);
|
||||
|
||||
if (is_dir($translationsPath)) {
|
||||
$this->loadTranslationsFrom($translationsPath, 'module.'.Str::kebab($module->name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load module commands
|
||||
*/
|
||||
public function loadModuleCommands(): void
|
||||
{
|
||||
if (! $this->app->runningInConsole()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$commands = [];
|
||||
$commandFiles = glob(modules_path('Core/Commands/').'*.php');
|
||||
|
||||
if (! $commandFiles) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($commandFiles as $commandFile) {
|
||||
$commandClass = 'App\\Modules\\Core\\Commands\\'.pathinfo($commandFile, PATHINFO_FILENAME);
|
||||
|
||||
if (class_exists($commandClass)) {
|
||||
$commands[] = $commandClass;
|
||||
}
|
||||
}
|
||||
|
||||
$this->commands($commands);
|
||||
}
|
||||
}
|
||||
10
app/Modules/OrderStatus/Interfaces/HasStatus.php
Normal file
10
app/Modules/OrderStatus/Interfaces/HasStatus.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\OrderStatus\Interfaces;
|
||||
|
||||
/**
|
||||
* @property string $status
|
||||
*
|
||||
* @phpstan-require-extends \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
interface HasStatus {}
|
||||
64
app/Modules/OrderStatus/OrderStatusModule.php
Normal file
64
app/Modules/OrderStatus/OrderStatusModule.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\OrderStatus;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class OrderStatusModule 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 [];
|
||||
}
|
||||
}
|
||||
120
app/Modules/OrderStatus/Repositories/OrderStatusRepository.php
Normal file
120
app/Modules/OrderStatus/Repositories/OrderStatusRepository.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\OrderStatus\Repositories;
|
||||
|
||||
class OrderStatusRepository
|
||||
{
|
||||
/**
|
||||
* Pending orders are brand new orders that have not been processed yet.
|
||||
*/
|
||||
public const PENDING = 'pending';
|
||||
|
||||
/**
|
||||
* Orders that has been registered..
|
||||
*/
|
||||
public const REGISTER = 'register';
|
||||
|
||||
/**
|
||||
* Orders that has been registered..
|
||||
*/
|
||||
public const PROCESSING = 'processing';
|
||||
|
||||
/**
|
||||
* Orders fulfilled completely.
|
||||
*/
|
||||
public const COMPLETED = 'completed';
|
||||
|
||||
/**
|
||||
* Order that has been cancelled.
|
||||
*/
|
||||
public const CANCELLED = 'cancelled';
|
||||
|
||||
/**
|
||||
* Mobile device
|
||||
*/
|
||||
public const MOBILE_DEVICE = 'mobile';
|
||||
|
||||
/**
|
||||
* Default status value
|
||||
*/
|
||||
public static function defaultStatus(): string
|
||||
{
|
||||
return static::PENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Status Values
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function statusValues(): array
|
||||
{
|
||||
return [
|
||||
null => '-',
|
||||
self::PENDING => __('Pending'),
|
||||
self::REGISTER => __('Registered'),
|
||||
self::PROCESSING => __('Processing'),
|
||||
self::COMPLETED => __('Completed'),
|
||||
self::CANCELLED => __('Cancelled'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tailwind
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function statusClasses(): array
|
||||
{
|
||||
return [
|
||||
null => '-',
|
||||
self::PENDING => 'warning',
|
||||
self::REGISTER => 'info',
|
||||
self::PROCESSING => 'info',
|
||||
self::COMPLETED => 'success',
|
||||
self::CANCELLED => 'danger',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Status icons
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function statusIcons(): array
|
||||
{
|
||||
return [
|
||||
null => '-',
|
||||
'success' => 'check-circle',
|
||||
'info' => 'information-circle',
|
||||
'primary' => 'clipboard-list',
|
||||
'danger' => 'ban',
|
||||
'warning' => 'exclamation-circle',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* HEX Colors
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function statusColors(): array
|
||||
{
|
||||
return [
|
||||
null => '-',
|
||||
self::PENDING => '#F5573B',
|
||||
self::REGISTER => '#F2CB22',
|
||||
self::PROCESSING => '#8FC15D',
|
||||
self::COMPLETED => '#098F56',
|
||||
self::CANCELLED => '#d70206',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted status for given "status"
|
||||
*/
|
||||
public static function statusFormatted(string $status = 'pending'): string
|
||||
{
|
||||
return static::statusValues()[$status] ?? __('None');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'apple_testing_phone' => '61126667',
|
||||
'apple_testing_code' => 77777,
|
||||
'min_code' => 10000,
|
||||
'max_code' => 99999,
|
||||
'message' => 'Tassyklaýyş belgi: :code',
|
||||
'validation_message' => 'Tassyklaýyş belgi nädogry.',
|
||||
'no_username_or_code_message' => 'Telefon belgisi ýa-da tassyklaýyş belgisi ýok.',
|
||||
];
|
||||
@@ -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('otp_verifications', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('username');
|
||||
$table->string('code');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('otp_verifications');
|
||||
}
|
||||
};
|
||||
26
app/Modules/OtpVerification/Models/OtpVerification.php
Normal file
26
app/Modules/OtpVerification/Models/OtpVerification.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\OtpVerification\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $username
|
||||
* @property string $code
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*/
|
||||
class OtpVerification extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected $table = 'otp_verifications';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = ['username', 'code'];
|
||||
}
|
||||
72
app/Modules/OtpVerification/OtpVerificationModule.php
Normal file
72
app/Modules/OtpVerification/OtpVerificationModule.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\OtpVerification;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
use App\Modules\Core\ModulePackageType;
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class OtpVerificationModule 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 [
|
||||
new ModulePackage(
|
||||
type: ModulePackageType::MODULE,
|
||||
name: 'Sms',
|
||||
message: 'For sending sms verification codes.',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\OtpVerification\Repositories;
|
||||
|
||||
use App\Modules\OtpVerification\Models\OtpVerification;
|
||||
use App\Modules\Sms\Repositories\SmsRepository;
|
||||
|
||||
class OtpVerificationRepository
|
||||
{
|
||||
/**
|
||||
* Send a sms verification
|
||||
*/
|
||||
public static function sendSMSVerification(string|int $phone_number): ?OtpVerification
|
||||
{
|
||||
abort_unless(module('Sms')->isEnabled(), 500, 'Sms module is not enabled');
|
||||
|
||||
/* for apple testing */
|
||||
$phone_code = ($phone_number == config('module.otp-verification.apple_testing_phone'))
|
||||
? config()->integer('module.otp-verification.apple_testing_code')
|
||||
: rand(config()->integer('module.otp-verification.min_code'), config()->integer('module.otp-verification.max_code'));
|
||||
|
||||
$verification = OtpVerification::where(['username' => $phone_number])->first();
|
||||
$verification
|
||||
? $verification->update(['code' => $phone_code])
|
||||
: OtpVerification::create(['username' => $phone_number, 'code' => $phone_code]);
|
||||
|
||||
SmsRepository::sendSMS($phone_number, str_replace(':code', (string) $phone_code, config()->string('module.otp-verification.message')));
|
||||
|
||||
return $verification;
|
||||
}
|
||||
}
|
||||
33
app/Modules/OtpVerification/Rules/OtpVerificationRule.php
Normal file
33
app/Modules/OtpVerification/Rules/OtpVerificationRule.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\OtpVerification\Rules;
|
||||
|
||||
use App\Modules\OtpVerification\Models\OtpVerification;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class OtpVerificationRule implements ValidationRule
|
||||
{
|
||||
public function __construct(
|
||||
protected null|int|string $username
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! $this->username || ! $value) {
|
||||
$fail(config()->string('module.otp-verification.no_username_or_code_message'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
OtpVerification::query()
|
||||
->where('username', $this->username)
|
||||
->where('code', $value)
|
||||
->firstOr(fn () => $fail(config()->string('module.otp-verification.validation_message')));
|
||||
}
|
||||
}
|
||||
12
app/Modules/OtpVerification/otp-verification-helpers.php
Normal file
12
app/Modules/OtpVerification/otp-verification-helpers.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\OtpVerification\Models\OtpVerification;
|
||||
use App\Modules\OtpVerification\Repositories\OtpVerificationRepository;
|
||||
|
||||
/**
|
||||
* Send a sms verification
|
||||
*/
|
||||
function sendSMSVerification(string|int $phone_number): ?OtpVerification
|
||||
{
|
||||
return OtpVerificationRepository::sendSMSVerification($phone_number);
|
||||
}
|
||||
64
app/Modules/PersonStates/PersonStatesModule.php
Normal file
64
app/Modules/PersonStates/PersonStatesModule.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\PersonStates;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class PersonStatesModule 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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\PersonStates\Repositories;
|
||||
|
||||
class EducationRepository
|
||||
{
|
||||
public const SCHOOL_DROP_OUT = 'school_drop_out';
|
||||
|
||||
public const SCHOOL = 'school';
|
||||
|
||||
public const MIDDLE_SCHOOL = 'middle_school';
|
||||
|
||||
public const UNFINISHED_HIGH_EDUCATION = 'Unfinished_high_education';
|
||||
|
||||
public const HIGH_EDUCATION = 'high_education';
|
||||
|
||||
public const MASTERS = 'masters';
|
||||
|
||||
public const PHD = 'phd';
|
||||
|
||||
/**
|
||||
* Education statuses
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return [
|
||||
self::SCHOOL_DROP_OUT => __('School drop out'),
|
||||
self::SCHOOL => __('School'),
|
||||
self::MIDDLE_SCHOOL => __('Middle school'),
|
||||
self::UNFINISHED_HIGH_EDUCATION => __('Unfinished high education'),
|
||||
self::HIGH_EDUCATION => __('High education'),
|
||||
self::MASTERS => __('Masters ED'),
|
||||
self::PHD => __('PHD'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default education status
|
||||
*/
|
||||
public static function default(): string
|
||||
{
|
||||
return self::HIGH_EDUCATION;
|
||||
}
|
||||
}
|
||||
40
app/Modules/PersonStates/Repositories/MarriageRepository.php
Normal file
40
app/Modules/PersonStates/Repositories/MarriageRepository.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\PersonStates\Repositories;
|
||||
|
||||
class MarriageRepository
|
||||
{
|
||||
public const MARRIED = 'married';
|
||||
|
||||
public const LEGAL_MARRIAGE = 'legal_marriage';
|
||||
|
||||
public const DIVORCED = 'divorced';
|
||||
|
||||
public const WIDOW = 'WIDOW';
|
||||
|
||||
public const SINGLE = 'single';
|
||||
|
||||
/**
|
||||
* Marriage values
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return [
|
||||
self::MARRIED => __('Married'),
|
||||
self::LEGAL_MARRIAGE => __('Legal Marriage'),
|
||||
self::DIVORCED => __('Divorced'),
|
||||
self::WIDOW => __('Widow'),
|
||||
self::SINGLE => __('Single'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default marriage value
|
||||
*/
|
||||
public static function default(): string
|
||||
{
|
||||
return self::MARRIED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\PhoneNumberVerification;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class PhoneNumberVerificationModule 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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\PhoneNumberVerification\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class PhoneNumberVerificationRule implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$value = preg_replace('/\D/', '', $value); // @phpstan-ignore-line
|
||||
|
||||
if (! is_numeric($value)) {
|
||||
$fail('Telefon belgisi diňe sanlardan ybarat bolmaly.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$number = (int) $value;
|
||||
|
||||
$isValid = ($number >= 61000000 && $number <= 65999999) || ($number >= 71000000 && $number <= 71999999);
|
||||
|
||||
if (! $isValid) {
|
||||
$fail('Telefon belgisi nädogry aralykda.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Unmask turkmen number
|
||||
*/
|
||||
function unMaskTurkmenNumber(string|int $number): string
|
||||
{
|
||||
return Str::of((string) $number)
|
||||
->replaceMatches('/[^\d]/', '') // keep only digits
|
||||
->whenStartsWith('993', fn ($str) => $str->after('993'))
|
||||
->value();
|
||||
}
|
||||
36
app/Modules/Province/Controllers/ProvinceController.php
Normal file
36
app/Modules/Province/Controllers/ProvinceController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Modules\Province\Models\Province;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProvinceController extends Controller
|
||||
{
|
||||
/**
|
||||
* LIST provinces (etraplar)
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'groupBy' => ['nullable', 'string', 'in:region'],
|
||||
]);
|
||||
|
||||
$provinces = Province::query()
|
||||
->where('active', true)
|
||||
->get()
|
||||
->map(fn (Province $province) => [
|
||||
'id' => $province->id,
|
||||
'name' => $province->name,
|
||||
'region' => $province->region,
|
||||
]);
|
||||
|
||||
if ($request->filled('groupBy')) {
|
||||
$provinces = $provinces->groupBy('region');
|
||||
}
|
||||
|
||||
return response()->json($provinces);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('provinces', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('region');
|
||||
$table->json('name');
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('provinces');
|
||||
}
|
||||
};
|
||||
42
app/Modules/Province/Models/Province.php
Normal file
42
app/Modules/Province/Models/Province.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $region
|
||||
* @property array<string, string> $name
|
||||
* @property bool $active
|
||||
* @property \Illuminate\Support\Carbon $created_at
|
||||
* @property \Illuminate\Support\Carbon $updated_at
|
||||
*/
|
||||
class Province extends Model
|
||||
{
|
||||
use HasTranslations;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'provinces';
|
||||
|
||||
/**
|
||||
* Translatable fieldsg
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public $translatable = ['name'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'active' => 'boolean',
|
||||
];
|
||||
}
|
||||
64
app/Modules/Province/ProvinceModule.php
Normal file
64
app/Modules/Province/ProvinceModule.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class ProvinceModule 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 [];
|
||||
}
|
||||
}
|
||||
5
app/Modules/Province/Repositories/ProvinceRepository.php
Normal file
5
app/Modules/Province/Repositories/ProvinceRepository.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province\Repositories;
|
||||
|
||||
class ProvinceRepository {}
|
||||
6
app/Modules/Province/Resources/Lang/tk/base.php
Normal file
6
app/Modules/Province/Resources/Lang/tk/base.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Province' => 'Etrap',
|
||||
'Provinces' => 'Etraplar',
|
||||
];
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user