diff --git a/app/Events/EventType.php b/app/Events/EventType.php index 1c01426..37d6768 100644 --- a/app/Events/EventType.php +++ b/app/Events/EventType.php @@ -2,6 +2,8 @@ namespace App\Events; +use Laravel\Nova\Actions\ActionEvent; + class EventType { /** @@ -56,9 +58,27 @@ class EventType ]; } + /** + * Laravel nova events + */ + public static function laravelNovaEvents(): array + { + return [ + self::laravelNovaActionEvent(), + ]; + } + + /** + * Laravel nova action event + */ + public static function laravelNovaActionEvent(): string + { + return ActionEvent::class; + } + /** * Guest the event - * @param object $event + * @param string|object $event */ public static function guessEvent(string|object $event): string { diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 5402ea1..a3f0c5f 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -1,5 +1,6 @@ info(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', + '%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('app.name'), $request->method(), @@ -77,5 +78,45 @@ function storeAuthEvent(string $name, Request $request): void $request->host(), $request->getPort(), 'tk', + $request->user()->id ?? '-', )); } + +/** + * Store resource events + */ +function storeResourceEvent(string $name, array $data, Request $request): void +{ + if ($name === EventType::laravelNovaActionEvent() || empty($data)) { + return; + } + + try { + $before = []; + $after = []; + foreach ($data[0]->getChanges() as $key => $value) { + $before[] = [$key => $data[0]->getOriginal()[$key]]; + $after[] = [$key => $value]; + } + + Log::channel('resource_activity') + ->info(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, MODEL_NAME: %s, BEFORE: %s, AFTER: %s', + $name, + config('app.name'), + $request->method(), + $request->ip(), + $_SERVER['REMOTE_PORT'], + $request->url(), + $request->host(), + $request->getPort(), + 'tk', + $request->user()->id ?? '-', + get_class($data[0]), + json_encode($before), + json_encode($after), + )); + } catch (Exception $e) { + Log::error('Error in storeResourceEvent() helpers', $e); + } +} diff --git a/app/Nova/Resources/Branch/Branch.php b/app/Nova/Resources/Branch/Branch.php index a9f5a47..3dceac3 100644 --- a/app/Nova/Resources/Branch/Branch.php +++ b/app/Nova/Resources/Branch/Branch.php @@ -10,6 +10,7 @@ use App\Repos\System\Settings\Location\RegionRepo; use Illuminate\Http\Request; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Select; +use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\Text; use Laravel\Nova\Fields\Textarea; use Laravel\Nova\Http\Requests\NovaRequest; @@ -94,7 +95,7 @@ class Branch extends Resource Textarea::make(__('Address'), 'address'), - NovaSwitcher::make(__('Active'), 'active') + Boolean::make(__('Active'), 'active') ->default(true), ]; } diff --git a/app/Nova/Resources/Order/Card/CardState.php b/app/Nova/Resources/Order/Card/CardState.php index 2f4ef11..6fa5ead 100644 --- a/app/Nova/Resources/Order/Card/CardState.php +++ b/app/Nova/Resources/Order/Card/CardState.php @@ -7,6 +7,7 @@ use App\Nova\Resource; use Illuminate\Http\Request; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Text; +use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Http\Requests\NovaRequest; use Trin4ik\NovaSwitcher\NovaSwitcher; @@ -69,7 +70,7 @@ class CardState extends Resource Text::make(__('Notes'), 'notes') ->rules('nullable', 'string', 'max:255'), - NovaSwitcher::make(__('Active'), 'active') + Boolean::make(__('Active'), 'active') ->default(true), ]; } diff --git a/app/Nova/Resources/Order/Card/CardType.php b/app/Nova/Resources/Order/Card/CardType.php index 5f93631..2d0d882 100644 --- a/app/Nova/Resources/Order/Card/CardType.php +++ b/app/Nova/Resources/Order/Card/CardType.php @@ -9,6 +9,7 @@ use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; use Trin4ik\NovaSwitcher\NovaSwitcher; +use Laravel\Nova\Fields\Boolean; class CardType extends Resource { @@ -69,7 +70,7 @@ class CardType extends Resource Text::make(__('Notes'), 'notes') ->rules('nullable', 'string', 'max:255'), - NovaSwitcher::make(__('Active'), 'active') + Boolean::make(__('Active'), 'active') ->default(true), ]; } diff --git a/app/Nova/Resources/Order/Loan/LoanOrder.php b/app/Nova/Resources/Order/Loan/LoanOrder.php index 0888248..761de86 100644 --- a/app/Nova/Resources/Order/Loan/LoanOrder.php +++ b/app/Nova/Resources/Order/Loan/LoanOrder.php @@ -165,51 +165,6 @@ class LoanOrder extends Resource Text::make(__('Note'), 'notes') ->fullWidth() ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), ]), new Panel(__('Loan'), [ diff --git a/app/Nova/Resources/Order/Loan/LoanType.php b/app/Nova/Resources/Order/Loan/LoanType.php index 5a7c4a7..b4de0a1 100644 --- a/app/Nova/Resources/Order/Loan/LoanType.php +++ b/app/Nova/Resources/Order/Loan/LoanType.php @@ -8,6 +8,7 @@ use App\Nova\Resource; use Illuminate\Http\Request; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Number; +use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; use Trin4ik\NovaSwitcher\NovaSwitcher; @@ -74,7 +75,7 @@ class LoanType extends Resource Text::make(__('Notes'), 'notes') ->rules('required', 'string', 'max:255'), - NovaSwitcher::make(__('Active'), 'active') + Boolean::make(__('Active'), 'active') ->default(true), ]; } diff --git a/app/Nova/Resources/System/Location/Province.php b/app/Nova/Resources/System/Location/Province.php index 3a8992b..31b38bc 100644 --- a/app/Nova/Resources/System/Location/Province.php +++ b/app/Nova/Resources/System/Location/Province.php @@ -8,6 +8,7 @@ use App\Nova\Filters\RegionFilter; use App\Nova\Resource; use App\Repos\System\Settings\Location\RegionRepo; use Illuminate\Http\Request; +use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Select; use Laravel\Nova\Fields\Text; @@ -75,7 +76,7 @@ class Province extends Resource ->translatable() ->rules('required', 'string', 'max:255'), - NovaSwitcher::make(__('Active'), 'active') + Boolean::make(__('Active'), 'active') ->default(true), ]; } diff --git a/app/Nova/User.php b/app/Nova/User.php index 50b4a4a..20cc5e1 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -14,6 +14,7 @@ use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\MorphToMany; use Laravel\Nova\Fields\Password; +use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; use Nurmuhammet\NovaInputmask\NovaInputmask; @@ -108,7 +109,7 @@ class User extends Resource ->creationRules('required', Rules\Password::defaults()) ->updateRules('nullable', Rules\Password::defaults()), - NovaSwitcher::make(__('Active'), 'active') + Boolean::make(__('Active'), 'active') ->default(true) ->canSeeWhen('isAdmin', $this), diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index d3fe39d..3032205 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider @@ -21,5 +22,9 @@ class AppServiceProvider extends ServiceProvider public function boot(): void { Model::shouldBeStrict(! app()->isProduction()); + + Event::listen(['eloquent.created: *', 'eloquent.updated: *', 'eloquent.deleted: *'], function(string $eventName, array $data) { + storeResourceEvent($eventName, $data, request()); + }); } } diff --git a/config/logging.php b/config/logging.php index a1d06a7..abb2436 100644 --- a/config/logging.php +++ b/config/logging.php @@ -134,6 +134,13 @@ return [ 'replace_placeholders' => true, ], + 'resource_activity' => [ + 'driver' => 'single', + 'path' => storage_path('logs/resource_activity.log'), + 'level' => 'info', + 'replace_placeholders' => true, + ], + 'halkbank_payment_error' => [ 'driver' => 'single', 'path' => storage_path('logs/halkbank_payment_error.log'),