Creating Dynamic Input fields with json data

I am creating dynamic multi fields with PHP and JSON data. I am facing issues like 1st the foreach is not showing the data with the same keys like “text” field it is showing the one only in foreach loop. it should show.

1: input field with data (type text)
2: Textarea field with data
3: inputfield with data (type text)

but it is only showing 2 fields when I am running the code. Where I am mistaking?
And how to show the fields with types if the type is text then show the <input type="text" with data> and if it is textarea then show <textarea with data></textarea> please some one can help me out with this?

$json_test_data = '
                {
                    "section_1":
                    [
                        {
                            "text":{"class":"mb-20","name":"text","value":"value 1","placeholder":"Section placeholder"}
                        },
                        {
                            "textarea":{"class":"mb-20","name":"section_content","value":"Section content 1","placeholder":"Section Content"}
                        },
                        {
                            "text":{"class":"mb-20","name":"value_2","value":"value 2 value","placeholder":"value 2 placeholder"}
                        }
                    ]
                }';
                $json_test = json_decode($json_test_data, true);
                $input = '';
                if(is_array($json_test))
                {
                    foreach ($json_test as $section => $section_data)
                    {
                        echo '<div class="model">';
                        echo '<div class="model-header d-flex"><h4>'.$section.' Data</h4></div>';
                        foreach($section_data as $section_fields => $fields_data)
                        {
                            foreach($fields_data as $field_key => $field_value)
                            {
                                if($field_key == 'text')
                                {
                                    foreach($field_value as $field_keyy => $field_valuee)
                                    {   
                                        $input .= $field_keyy.'="'.$field_valuee.'" ';
                                    }
                                    echo '<input '.$input.'>';
                                }
                                
                            }
                        }
                        echo '</div>';
                    }
                }

I tried to input data based on the selected checkbox but an error occurred when selecting the second data if the first data was not selected too

<td>
    <input type="number" name="qty_masuk[]" id="qty_masuk" class="form-control" placeholder="QTY">
</td>
<td>
    <div class="form-control">
        <input type="checkbox" id="id_barang" name="id_barang[]" value="<?php echo $st['id_barang']; ?>">
    </div>
</td>

code html view

public function add_selected_barang()
{
    if (isset($_POST['submit'])) {
        $id_barang = $_POST['id_barang'];
        $qty_masuk = $_POST['qty_masuk'];

        for ($i = 0; $i < count($id_barang); $i++) {
            if ($qty_masuk != NULL) {
                $category_id = $id_barang[$i];
                $category_qty = $qty_masuk[$i];
                $this->Po_model->multisave($category_id, $category_qty);
            }
            // 
            $this->session->set_flashdata('flash', 'Item baru berhasil ditambahkan');
            redirect('daftarproduk');
        }
    }
}

in this controller I try to get 2 or more data when the checkbox is selected, when all the data is checked there is no problem at all the data entered is correct according to the selected data, which becomes a problem when I try to input the 2nd data without checking the first data, qty_masuk the value becomes 0 which should follow the data entered by the user, the problem that occurs is in qty_masuk.

function multisave($id_barang, $qty_masuk)
{
    $query = "INSERT INTO `barang_masuk`( `id_barang`, `qty_masuk`) 
    VALUES ('$id_barang','$qty_masuk')";
    $this->db->query($query);
}

Model

what should be added to solve this problem?

Magento 2: Cannot getData from different controller

I have this class

class Api extends MagentoFrameworkModelAbstractModel
{
 public function __construct(
        MagentoFrameworkMessageManagerInterface $messageManager,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoStoreModelStoreManagerInterface $storeManager,
        MyModulePaymentHelperData $helper
    ) {
        $this->messageManager = $messageManager;
        $this->scopeConfig = $scopeConfig;
        $this->storeManager = $storeManager;
        $this->helper = $helper;
        $this->contentType = $this->helper->getConfigData('content_type');
    }
    .
    .
    .
    function createOnlinePurchase($authToken, $lastOrder)
    {
        .
        .
        .
        //here I pass lastOrder's increment id to my payment gateway
        $lastOrder->setData('test','test data');
        $lastOrder->save();
        
        //make payment gateway api call, get payment url
        return url;
    }

}

this class is then used by a custom controller:

class Index extends MagentoFrameworkAppActionAction
{
    public function __construct(
        MagentoFrameworkAppActionContext $context,
        MyModulePaymentModelApi $moduleApi,
        MagentoCheckoutModelSession $session
    ) {
        parent::__construct($context);

        $this->moduleApi = $moduleApi;
        $this->session = $session;
    }
   
 public function execute() {
       $token = $this->moduleApi->requestAuthToken();

       if ($this->session->getLastRealOrder() && $token !== null) {
            $url = $this->moduleApi->createOnlinePurchase($token, $this->session->getLastRealOrder());

            if ($url !== null && substr($url, 0, 4) == 'http') {
               $this->session->clearStorage();     
               return $this->resultRedirectFactory->create()->setUrl($url);
            } 
            else {
                $this->messageManager->addError(__("Url invalid: ".$url));
                return $this->resultRedirectFactory->create()->setPath('checkout/onepage/failure');
            }
       }
}

on a SECOND custom controller Callback, which is triggered by my payment gateway, I retrieved the order object using $order = $this->getOrderFactory->create()->loadByIncrementId($incrementId)

where $this->getOrderFactory is an instance of MagentoSalesModelOrderFactory I injected.

I got the increment id back from my payment gateway.

Somehow within this Callback class, when I use $order->getData('test'), I get nothing

My question is

Is there some core magento concept I’m missing here?

Or is there any other way I can retrieve this test data in Callback which only have the information of increment Id (because at the point of Callback, user have already left magento and come back)

It’s weird to me beause I can edit and save the order from Callback but my extra data is not saved/associated with the order object itself

Thanks in advance!

Laravel model with multiple where condition getting unclear data

Hello everyone i want to ask about my problem. I want to get which data if column a is b or column b is a for a messaging app. I think you will understand when you see the code. And I also think I did nothing wrong in writing the code. this is my code and the response

Variable for this test

var uid: "QqAIR5Qwd6erFQIgSG"
var friend_uid: "Pk6R56XmWMywcObV3a"

Test 1

Chat::where(['sender'=>$request->uid, 'receiver'=>$request->friend_uid])->get();

Response

"data": [
    {
        "id": 4,
        "sender": "QqAIR5Qwd6erFQIgSG",
        "receiver": "Pk6R56XmWMywcObV3a",
        "message": "eyJpdiI6Ik8xSld4QlQ3bmMxaWxBMVlua3B0WXc9PSIsInZhbHVlIjoidGMvNGpXVmowVDczRUhSdGM0UkFQNHNjSVVZcFEyeFJlRThWNGdhMWZQMUFodkIwNWJtNmg4cmg1T2NOTm5ZdXBkdzdWWWhUY3hDQUtnVFBGcHllMkE9PSIsIm1hYyI6IjRkYTI5OTk3ZTRhMDAwZTdkYzgwODVmOTgyYzdlYTY2NDg0ZGM2YmExMDVkYzdiMzRhOTliYjA2MjU1ZTc3ZTkiLCJ0YWciOiIifQ==",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    }
]

This is valid response

Test 2

Chat::where(['sender'=>$request->friend_uid, 'receiver'=>$request->uid])->get();

Response

"data": []

This is valid because it doesn’t exist in the database, if there is then he will appear I’ve tried it.

Test 3 (i want to do this)

Chat::where(['sender'=>$request->uid, 'receiver'=>$request->friend_uid])->orWhere('sender'=>$request->friend_uid, 'receiver'=>$request->uid)->get();

Response

"data": [
    {
        "id": 2,
        "sender": "30B67S1tV7O7sJRG2l",
        "receiver": "QqAIR5Qwd6erFQIgSG",
        "message": "eyJpdiI6IkFDaFNMNjZESk96ZU5rSTQyMVhOUEE9PSIsInZhbHVlIjoiaDZyZU9TRSs2c0VTdkVlU2ZDd2JvZHpvQTh3KzZIYjk0NWJrbm90Tk9WREhBV2lrTS9xQW9KOXIza0MwaHUyMGUrTnlBS21aNXBRd1BweXJldlhiOWkzR0hqeHlFWERpdXczZ1E4NTJCSUU9IiwibWFjIjoiMzA3YmQwZmM4NjFlOTk3YmQwNzMwMzgxMTQ4ZmRhZDBhY2IzOWJkZWMzYWVhZmQyNjQ2NGI1MzM4NDQ2ZWY4YiIsInRhZyI6IiJ9",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    },
    {
        "id": 4,
        "sender": "QqAIR5Qwd6erFQIgSG",
        "receiver": "Pk6R56XmWMywcObV3a",
        "message": "eyJpdiI6Ik8xSld4QlQ3bmMxaWxBMVlua3B0WXc9PSIsInZhbHVlIjoidGMvNGpXVmowVDczRUhSdGM0UkFQNHNjSVVZcFEyeFJlRThWNGdhMWZQMUFodkIwNWJtNmg4cmg1T2NOTm5ZdXBkdzdWWWhUY3hDQUtnVFBGcHllMkE9PSIsIm1hYyI6IjRkYTI5OTk3ZTRhMDAwZTdkYzgwODVmOTgyYzdlYTY2NDg0ZGM2YmExMDVkYzdiMzRhOTliYjA2MjU1ZTc3ZTkiLCJ0YWciOiIifQ==",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    },
    {
        "id": 87,
        "sender": "chT9eSJ0N6HAXlkUUL",
        "receiver": "QqAIR5Qwd6erFQIgSG",
        "message": "eyJpdiI6Ikd4ZFZZTE1IVXRGQXNCVmUxUmJhcUE9PSIsInZhbHVlIjoiNWNUZE91Mk41K2o5Si9TSktOdEpNVSswYlVXZDlQd2hyTWY0d256cEJ4YkZKNVg0Y2hwbmNiUTJkZFhMSGxzVSIsIm1hYyI6IjA5ZDk2MDNkYzFhYzY0MTNlNTM3ODNmZDFiZDU3OTc2NThkODg4MGQzZGM5ZWQyYWRjM2Q1YzJmODkwNmUwOTYiLCJ0YWciOiIifQ==",
        "created_at": "2022-03-02T09:29:44.000000Z",
        "updated_at": "2022-03-02T09:29:44.000000Z"
    }
]

why when I try with a query like this I get data which doesn’t match the uid or friend_uid? what happened and if where is the error in my program?, please help, thank you.

Play Sound when value matched

Hello I have a simple script below where the value if MATCHED will echo message, but I want to create a script from this that instead of message it will sound or play audio file when the value is matched here below is the script sorry if I put the script sample inappropriate TY

<?php
// weather disturbance checker script
$imagesDir = './ajax-images/';  // directory for ajax-images with trailing slash
$MayBagyo = file_get_contents('./cache/typhoonsector3.txt');
$products = str_word_count($MayBagyo, 1);

$bagyostatus = 'wp9'; // when matched

$cyclonefound = false;
foreach ($products as $product)

{
    if (strpos($bagyostatus,$product) !== false) {
        $cyclonefound = true;
        break;
    }
}

if ($cyclonefound) {
    //echo 'A Low Pressure Area is Detected';
   echo "sound will play"/>";
}
else {
    echo '"message will post';

}
// end of weather disturbance checker script
?>

php script generating new pw to PlayFab

This is my first php script ever and I have googled a lot to try to get the script to work.

I am working on this tutorial: https://docs.microsoft.com/en-us/gaming/playfab/features/engagement/emails/using-email-templates-to-send-an-account-recovery-email

<!DOCTYPE HTML>  
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>  

<?php
// define variables and set to empty values
$emailErr = $pw1Err = $pw2Err = "";
$email = $pw1 = $pw2 = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

  if (empty($_POST["email"])) 
  {
    $emailErr = "Email is required";
  } 
  else 
  {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format";
    }
  }

  if (empty($_POST["pw1"])) 
  {
    $pw1Err = "Password is required";
  }

  if (empty($_POST["pw2"])) {
    $pw2Err = "Confirm Password is required";
  }


//$str1 = "Hello";
//$str2 = "Hello World";
//echo strcasecmp($pw11, $pw2); // Outputs: -6


//$check = strcasecmp($pw11, $pw2)

$check = strcasecmp($pw1, $pw2); // Outputs: -6

/*
  if ($check == 0)
  {
      <br><br>
      echo Passwords are the same!;
      <br><br>
  }
  else
  {
      <br><br>
      echo Passwords are NOT the same!;
      <br><br>
  }
  */

}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<h2>Password Recovery</h2>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo     htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  E-mail: <input type="text" name="email" value="<?php echo   $email;?>">
  <span class="error">* <?php echo $emailErr;?></span>
  <br><br>
  New Password: <input type="test_input" name=pw1 valur="<?php echo $pw1;?>">
  <span class="error">* <?php echo $pw1Err;?></span>
  <br><br>
  Confirm Password: <input type="test_input" name=pw2 valur="<?  php echo $pw2;?>">
  <span class="error">* <?php echo $pw2Err;?></span>
  <br><br><br>
  <input type="submit" name="submit" value="Submit">  
</form>

<?php
echo "<br>";
echo "<h3>Your Input:</h3>";
echo $email;
echo "<br>";
echo $check;
?>

</body>
</html>

What I am trying to accomplish is the callback URL. I first tried to create it in WordPress, which was also a first, and now try with php code.

Here is what I try to accomplish:

A form with the following fields:

  1. email
  2. New pasword (currently a text_input during test but will be real pw)
  3. Confirm password (currently a text_input during test but will be real pw)
  4. Submit button

Currently I am focus on trying to echo the result but I just can’t get this to work.

The ultimate target is to send back a confirmation with this API including the new checked password and the token.

https://docs.microsoft.com/en-us/rest/api/playfab/admin/account-management/reset-password?view=playfab-rest

I have been trying for quite a long time now so I reach out for help.

Call to a member function forceFill() on null, PersonalAccessTokenFactory.php

When I tried to use oauth laravel authentication, it produces the following error.I tried restarting redis and laravel server.Kindly help me to fix this issue.

  {
    "status": "error",
    "message": "{"status":"error","type":"exception","message":"Call to a member function forceFill() on null","file":"\/srv\/vendor\/laravel\/passport\/src\/PersonalAccessTokenFactory.php","line":78}"
}

Laravel worker set dynamic retry_after

Have a Laravel 5.7 app with a single Job class. The job itself will fetch data and process it.
The amount of data (and therefore the length of time the job takes) can vary massively so wanted to have a dynamic timeout based on the runtime of the past n jobs (the details are stored so can be queried).

This would work in that I can set public $timeout = n in the class but the retry_after value can only be set on CLI or in the config/queue.php as the public $retryAfter in the class has a different function (according to https://divinglaravel.com/explaining-laravel-queue-configuration-keys).

Is there any way that at runtime I can set the retry_after value dynamically?

For info, absolutely cannot hard set a value due to the way the app works (and refactoring other code in the app is a no-go), and the time it takes to run will always be an unknown so just creating separate long running queues or things like that won’t work either.

Laravel Receipt pdf download

I’m using laraveldaily/laravel-invoices to generate invoices.

I’ve stored the receipt with ->save('public'); and stored this link to database with: $invoice->url().

I got a link like this: http://example.com/storage/pdf_name.pdf .
But, File stored in storage/app/public/ folder

Now, If I hit this URL, it says **"Forbidden"** You don't have permission to access this resource.

What can I do now? and is there any way to store just folder and file name? like: folder/pdf_name.pdf

WordPress Directory Issues

All WordPress core files had a wrong file directory like this. So I am facing the below error on wordpress admin panel

Error
wp-blog-header.php
Warning: Use of undefined constant ABSPATH – assumed ‘ABSPATH’ (this will throw an Error in a future version of PHP) in E:xampphtdocsdcidigital_blogwp-adminindex.php on line 13

Warning: require_once(ABSPATHwp-admin/includes/dashboard.php): failed to open stream: No such file or directory in E:xampphtdocsdcidigital_blogwp-adminindex.php on line 13

Fatal error: require_once(): Failed opening required ‘ABSPATHwp-admin/includes/dashboard.php’ (include_path=’E:xamppphpPEAR’) in E:xampphtdocsdcidigital_blogwp-adminindex.php on line 13

All core file had like this 
require_once( dirname( __FILE__ ) . '/admin.php' );

Please check and give me some solutions

Retrieve in Laravel Blade data of external api with HTTP request

In my controller i have this

     public function GetStatusDetails()
        {
     $statusDetailsResponse = 
    Http::get('https://exemple.exemple.com/fr/api/088b77/<Token>/availability/<ID>/getStatusDetailsformat=json');
        $StatusDetails = json_decode($statusDetailsResponse->body(), true);
        }
dd($StatusDetails);

The result of the DD is Here

The question is how i acces to that data in my blade please ?

How to Convert All Word’s First Letter into Big Letter and Remaining in Small Letter if whole words are in Uppercase?

I am trying to change the first Letter of Each Word into Big Letter and Remaining Small in the following case if whole words are in Big Letters.

Example: THIS IS A CAT:

Output Require: This Is A Cat.

<style>    
/*not working if all words are in UPPERCASE.*/
text-transform: capitalize; 
</style>

/*PHP not working*/
<?PHP ucword(); ?>

Robot journalists in php [closed]

Good time of day. Has anyone met the source code of the script that writes news to the site? I’ve found similar things in other programming languages, but I’m interested in php.