Guest User

afterStateUpdated()

a guest
Aug 24th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1.  Forms\Components\TextInput::make('loan_amount')
  2.                             ->required()
  3.                             ->prefix('₱')
  4.                             ->label('Loan Amount')
  5.                             ->live(onBlur: true)
  6.                             ->numeric()
  7.                             ->afterStateUpdated(function ($state, $set, $get) {
  8.  
  9.                                 $loanType = $get('loan_type');
  10.  
  11.                                 switch ($loanType) {
  12.                                     case 'Sangla Below 5,000':
  13.                                         $set('copy_capitalBuildUp', 0.03);
  14.                                         $set('copy_savings_deposit_2', 0.02);
  15.                                         $set('copy_savings_deposit', 0.02);
  16.                                         $set('copy_interest', 0.01);
  17.                                         $set('copy_service_fee', 0.025);
  18.                                         break;
  19.  
  20.                                     case 'Sangla Above 5,000':
  21.                                         $set('copy_capitalBuildUp', 0.03);
  22.                                         $set('copy_savings_deposit_2', 0.02);
  23.                                         $set('copy_interest', 0.01);
  24.                                         $set('copy_service_fee', 0.025);
  25.                                         $set('copy_insurance', 0.85);
  26.                                         break;
  27.                                 }
  28.                             }),
  29.  
  30.   Forms\Components\TextInput::make('copy_capitalBuildUp')
  31.                                 ->label('Capital Build Up')
  32.                                 ->numeric()
  33.                                 ->live()
  34.  
  35.                 // I should use other method here since this was already define by loan amount, I need some triggers here that once it change it will update the capitalBuildUp
  36.                                 ->afterStateUpdated(function($state, $get, $set){
  37.                                     $loanAmount = $get('loan_amount');
  38.                                     $total = $loanAmount * $state;
  39.                                     $set('capitalBuildUp', 'test');
  40.                                 }),
  41.  
  42.  Forms\Components\TextInput::make('capitalBuildUp')
  43.                                 ->readOnly()
  44.                                 ->label('Capital Build Up')
  45.                                 ->numeric(),
Advertisement
Add Comment
Please, Sign In to add comment