@php tag in blade template can’t reach inline variable

I am looping through products which has all my configurable options available. Inside that i am looping through my items, when i get a match in product i want to display this product and item.

To do so i want to create a variable called $currentProduct.

@foreach($order['products'] as $product) // Configurable products
    @foreach($order['items'] as $item)  // Simple products
        @if ($item['product_type'] == 'simple')
            @if ($product['id'] === $item['product_id'])
                @php($currentProduct = $product) // error here $product undefined
                @php($currentItem = $item) // error here $item undefined
            @endif
        @elseif ($item['product_type'] == 'configurable')
            @if ($product['id'] == $item['parent_item']['product_id'])
                @php($currentProduct = $product) // error here $product undefined
                @php($currentItem = $item) // error here $item undefined
            @endif
        @endif
    @endforeach
@endforeach

I am new to laravel and blade templates and can’t seem to wrap my head around, why $product and $item is undefined when they are defined right above in same template.

Any help appreciated

how to display and hide the watermark on a video using ffmpeg

i’m new to ffmpeg i want to add any animation to the watermark
this is my php code:

$source=$_SERVER['DOCUMENT_ROOT']."/content/uploads/".$row['source'];
            $command = "ffmpeg -i ".$source." -i medada.png";
            $command .= " -filter_complex "[0:v][1:v]";
            $command .= " overlay=25:150""; 
            $str = rand();
            $result = hash("sha256", $str);
            $path_info = pathinfo($source);
            $extension=$path_info['extension'];
            $command .= " -c:a copy ".$_SERVER['DOCUMENT_ROOT']."/content/downloads/".$result.".".$extension."";

Unable to connect to localhost:2525

i’m trying to send email using google mail and i’m having this error i tried doing it with mailtrap it gaves me the same error
Connection could not be established with host localhost :stream_socket_client(): Unable to connect to localhost:2525 (No connection could be made because the target machine actively refused it)
i don’t know whats the relation between the localhost and the port 2525, i’m not trying to use the port this is my .env file

APP_ENV=local
APP_KEY=************************
APP_DEBUG=true
APP_URL=https:****************************

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=superett_super
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465  
[email protected]
MAIL_PASSWORD=GeForce7ThGen
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
MAIL_ENCRYPTION=tls

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

and this is my config/mail.php file i have already tried to change the host and the port in this file nothing works

<?php

return [
'default' => env('MAIL_MAILER', 'smtp'),

'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],

        'ses' => [
            'transport' => 'ses',
        ],

        'mailgun' => [
            'transport' => 'mailgun',
        ],

        'postmark' => [
            'transport' => 'postmark',
        ],

        'sendmail' => [
            'transport' => 'sendmail',
            'path' => '/usr/sbin/sendmail -bs',
        ],

        'log' => [
            'transport' => 'log',
            'channel' => env('MAIL_LOG_CHANNEL'),
        ],

        'array' => [
            'transport' => 'array',
        ],

        'failover' => [
            'transport' => 'failover',
            'mailers' => [
                'smtp',
                'log',
            ],
        ],
    ],

'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

php passing data form

i use get method to pass data from index.php to profile.php

index.php code is

<html>
<body>

<form action="profile.php" method="GET">
username: <input type="text" username="user"><br>
password: <input type="password" name="pass"><br>
<input type="submit">
</form>

<button type="button" onclick="alert('task success')"/>click me"</button>

</body>
</html>

profile.php code is

<?php
    echo " username: "$_GET ['username']."; password "$_GET['pass'];
?>

the output is
enter image description here

it pass the inputs of the form successfully but i need it to appear in profile.php file

how can i make the output appear in profile.php page?

any help please

Limesurvey: Redirection on wrong port

I’m currently working on setting up a LimeSurvey (version 5.1.17) inside a Kubernetes cluster. When trying to access the /admin/ endpoint it works perfectly, but if I try to reach /admin endpoint, I am getting redirected to http://<URL>:8080/admin, which is the port pods are listening to.

I have tried modifying the .htaccess file to rewrite the url from /admin to /admin/ but it didn’t do anything, I can’t even set a 403 on /admin, it will redirect me in any case. I also searched across the code but I couldn’t find where was the problem.
It might come from Traefik but it doesn’t look like it’s modifying urls.

Thanks for your help.

Convert animated gif to webp in PHP

Is it possible to convert an animated GIF to WEBP using Imagick?

$im = new Imagick();
$im->pingImage( _INTERNAL_FOLDER_ . $dir . "/" . $id . "/animation.gif" );
$im->readImage( _INTERNAL_FOLDER_ . $dir . "/" . $id . "/animation.gif" );
$im->setImageFormat( "webp" );
$im->setImageCompressionQuality( 80 );
$im->setOption( 'webp:lossless', 'false' );
$im->writeImage( _INTERNAL_FOLDER_ . $dir . "/" . $id . "/animation.webp" );

When I do it this way, I get only first frame from the GIF and not the whole animation. I know that WEBP format supports animation, however I was unable to find if Imagick has this ability too.

facebook connect Fb.getLoginStatus from php-sdk

I’m building an app with multiple subdomain for my users, since the Facebook JS SDK don’t allow wildcard on Authorized domains for the JavaScript SDK in App settings, I created an auth.example.com where I can authorize users with the php-sdk and save token in db I’m wondering if there is a way I can use the JS SDK with the access token from server-side, to be able to use the different methods of the JS SDK Such as FB.getLoginStatus, FB.login, FB.logout …, I tried to create the same cookie from the server-side but the php-sdk doesn’t return the signed request Any suggestions ?

Redirect specific user in Laravel after QR Code Scanned

I have a QR code generating link something like this https://example.com/6/4

Here:

=> 4 is ‘User ID

=> 6 is ‘Candidate ID

Means a user with only id 4 (after checking if he/she is logged in or not) should be redirect to a specific view with the details of candidate ID 6.

What i already have done:

  1. Check if that user ID is currently logged in or not!

  2. Candidate detail query with specific view.

I only need help how a specific user ID anywhere he is logged in can be redirected when this url is hit from controller?

Insert multiple rows with three single selects and one multiple select on each row

Every time the user clicks + a new row is added and when the user clicks x a new row is deleted user interface. There are four dropdowns. Month(single select) , Year(single select) , Main reason (single select), Secondary reason(multiple select). Main and secondary have the same id because they need to be inserted in the same column in database table structure

With the current code,only the first row inserted in database is correct (see second image). Everything else is messed up

PHP

if (isset($_POST[‘acute_id’]) && !empty($_POST[‘month_acute’]) && !empty($_POST[‘year_acute’]) ){

                array_push ($variations_cols, $db -> quoteName ('update_id') . ',' . $db -> quoteName ('acute_id')
                    . ',' . $db -> quoteName ('month_acute'). ',' . $db -> quoteName ('year_acute'));
                
                
                $unique_genes = array_unique ($_POST['acute_id'], SORT_NUMERIC); //remove duplicate genes
                $unique_keys  = array_keys ($unique_genes); // keys of unique values
                
            
                for ($i = 0; $i < count ($unique_genes); $i ++){
                    
                        array_push ($variations_vals, $db -> quote ($updated_id) . ',' . $db -> quote ($_POST['acute_id'][$i])
                            . ',' . $db -> quote ($_POST['month_acute'][$i]). ',' . $db -> quote ($_POST['year_acute'][$i]) );


                }

                insertIntoTable ($db, "patient_has_ac2", $variations_cols, $variations_vals);
            }

HTML

                                                <table id='acuteTable' class='table table-borderless acute_events_table enrol_dataset' style='display: none;'>
                                                <thead>
                                             
                                                </thead>
                                                <tbody>
                                               

                                                <tr class='acute_class text-center' style='display: none;'>
                                                    <th><label class='fw-bold control-label'><i class='error_asterisk'>*</i> Hospitalization/Emergency Admission Date</label></th>
                                                    <th><label class='fw-bold control-label'><i class='error_asterisk'>*</i> Main reason for each Hospitalization/Emergency admission</label></th>
                                                    <th><label class='fw-bold control-label'><i class='error_asterisk'>*</i> Secondary reason(s) for each Hospitalization/Emergency admission</label></th>
                                                    <th><button id='add_acute' type='button' class='btn btn-success'><i class='fa fa-plus'></i></button></th>
                                                </tr>
                                                
                                                <tr class='acute_class text-center' style='display: none;'>

                                                
                                                    <td class='form-group'>
                                                        <div class="row">
                                                            <select id='month_acute' name='month_acute[]' class='acute_date check_current_date month_check select2_cls form-control' style='width: fit-content;'>
                                                                    <option value=''>Month</option>
                                                                    <?php echo $month_list;  ?>
                                                            </select> 
                                                        
                                                            <select id='year_acute' name='year_acute[]' class='acute_date check_current_date year_check select2_cls form-control' style='width: fit-content;'>
                                                                    <option value=''>Year</option>
                                                                    <?php echo $year_list;  ?>
                                                            </select>
                                                        </div>  
                                                    </td>
                                                 
                                                   


                                                    <td class='form-group'>
                                                        <select id="select_other_primary1" name='acute_id[]' class='select2_cls acute_diagnosis genes form-control' style='width: 100%;'>
                                                            <?php echo $acute_complications; ?>
                                                        </select>
                                                        <div class='invalid-feedback feedback-icon'><i class='fa fa-times'></i> This is a <strong>mandatory</strong> field.</div>

                                                        <div class="other_primary1" style="display: none;"> 
                                                        <label class="control-label" for="transfusion_sel_past">
                                                            <i class="error_asterisk">*</i> Other main reason :
                                                        </label>
                                                        <textarea id="other_blood1" name="other_blood" class="form-control"></textarea>

                                                        </div>


                                                    </td>

                                                    <td class='form-group'>
                                                        <select name='acute_id[]' id="select_other_secondary2" class='select2_cls acute_diagnosis genes form-control' style='width: 100%;' multiple>
                                                            <?php echo $acute_complications; ?>
                                                        </select>
                                                        <div class='invalid-feedback feedback-icon'><i class='fa fa-times'></i> This is a <strong>mandatory</strong> field.</div>

                                                        <div class="other_secondary2" style="display: none;"> 
                                                        <label class="control-label" for="other_secondary2">
                                                            <i class="error_asterisk">*</i> Other secondary reason :
                                                        </label>
                                                        <textarea id="other_secondary_textarea2" name="other_secondary_textarea2" class="form-control"></textarea>

                                                        </div>


                                                    </td>




                                                    <!-- <td class='form-group'>
                                                        <select name='acute_secondary[]' class='select2_cls genotype_diagnosis allele_variations vars_select2 form-control' style='width: 100%;' data-placeholder='Select gene first'></select>
                                                        <div class="new_variation2" style="display: none;">
                                                            <input type="text" name="new_variation[]" class="new_variation_input2">
                                                        </div>
                                                        <div class='invalid-feedback feedback-icon'><i class='fa fa-times'></i> This is a <strong>mandatory</strong> field.</div>
                                                    </td> -->


                                                    
                                                </tr>

                                                </tbody>
                                            </table>

jQuery for adding rows

            $('#add_acute').off('click').on('click', function () {

            var acute_options = <?php echo json_encode ($acute_complications, JSON_UNESCAPED_SLASHES); ?>;

            var month_options = <?php echo json_encode ($month_list, JSON_UNESCAPED_SLASHES); ?>;

            var year_options = <?php echo json_encode ($year_list, JSON_UNESCAPED_SLASHES); ?>;



            $(".acute_events_table > tbody:last-child").append(
                '<tr class="acute_class text-center">' +



                '<td class="form-group">' +
                '<div class="row"> <select id="month_acute" name="month_acute[]" class="acute_date check_current_date month_check select2_cls form-control" data-placeholder="Month" style="width: fit-content;" ><option value="">Month</option>' +
                month_options + '</select><select id="year_acute" name="year_acute[]" class="acute_date check_current_date year_check select2_cls form-control" data-placeholder="Year"  style="width: fit-content;"  ><option value="">Year</option>' +
                year_options + '</select> </div>' +
                '<div class="invalid-feedback feedback-icon"><i class="fa fa-times"></i> This is a <strong>mandatory</strong> field.</div>' +
                '</td>'+



                '<td class="form-group">' +
                '<select name="acute_id[]" id="select_other_primary" class="select2_cls vars_select1 allele_variations acute_diagnosis form-control" style="width: 100%;" data-placeholder="Main reason" required>'+acute_options +'</select>' +
                '<div class="other_primary" style="display: none;"  >' +
                '<label class="control-label" for="other_primary_textarea"><i class="error_asterisk">*</i> Other main reason :</label>'+

                '<textarea id="other_primary_textarea" name="other_primary_textarea" class="form-control"></textarea>' +

                '</div>' +
                '<div class="invalid-feedback feedback-icon"><i class="fa fa-times"></i> This is a <strong>mandatory</strong> field.</div>' +
                '</td>'+



                '<td class="form-group">' +
                '<select name="acute_id[]" id="select_other_secondary" class="select2_cls vars_select2 allele_variations acute_diagnosis form-control" style="width: 100%;" data-placeholder="Secondary reason" required multiple>'+acute_options +'</select>' +
                '<div class="other_secondary" style="display: none;" >'+
                '<label class="control-label" for="other_secondary_textarea"><i class="error_asterisk">*</i> Other secondary reason :</label>'+
                '<textarea id="other_secondary_textarea" name="other_secondary_textarea" class="form-control"></textarea>'+
                
                '</div>'+
                '<div class="invalid-feedback feedback-icon"><i class="fa fa-times"></i> This is a <strong>mandatory</strong> field.</div>' +
                '</td>'+



                '<td><button type="button" class="btn btn-danger delete_row delete_row_causatives"><i class="fa fa-remove"></i></button></td>' +

                '</tr>'
            );

            $(".select2_cls").select2({width: 'resolve'}); //initialize select2 dropdowns

            });

            

How do I fix this stacked bar chart (Chart.js)

This is my controller

$productStock = Product::select('quantity', 'prodName', 'updated_at')->get()->groupBy(function($productStock){
    return Carbon::parse($productStock->updated_at)->format('M');
});

foreach($productStock as $month => $stock){
            $productMonth[] = $month;
           
            foreach($stock as $stockValue){
                $productName[] = $stockValue->prodName;
                $productQty[] = $stockValue->quantity;
            }
        }

return view('adminHome', ['productStock' => $productStock,
        'productMonth' => $productMonth, "productName" => $productName, "productQty" => $productQty]);

Javascript in blade file


<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

<script>
var product_Xaxis_data = JSON.parse('{!! json_encode($productMonth) !!}');
var product_Yaxis_data = JSON.parse('{!! json_encode($productQty) !!}');
var product_name_label = JSON.parse('{!! json_encode($productName) !!}');
function getRandomColor() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++) {
        color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
}

var ctx = document.getElementById("myBarChart");
var myLineChart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: product_Xaxis_data,
    datasets: [{
      label: product_name_label, 
      backgroundColor: getRandomColor(),
      borderColor: "rgba(2,117,216,1)",
      data: product_Yaxis_data, 
    }],
  },
  options: {
    scales: {
      xAxes: [{
        time: {
          unit: 'month'
        },
        gridLines: {
          display: false
        },
        ticks: {
          maxTicksLimit: 6
        },
         stacked: true
      }],
      yAxes: [{
        ticks: {
          min: 0,
          max: 200,
          maxTicksLimit: 6
        },
        gridLines: {
          display: true
        },
         stacked: true
      }],
    },
    legend: {
      display: false
    }
  }
});

</script>

This is the output is which is not what I wanted.
The bar did not stacked and end up merged together:
enter image description here

This is my desire output, The code below is just an example of how I wanted to get my desired output. Just need to replace with data in database:
enter image description here

 data: {
    labels: ["Dec"],
    datasets: [{
      label: "Metal Screw", 
      backgroundColor: getRandomColor(),
      borderColor: "rgba(2,117,216,1)",
      data: [100], 
    },
    {
      label: "Metal nut", 
      backgroundColor: getRandomColor(),
      borderColor: "rgba(2,117,216,1)",
      data: [80], 
    }],
  },

CakePHP unit testing repository function that returns method

trying to unit test a repository method that returns an object, and the test fixtures are arrays, the return value is an object.
Would the data in the test fixtures need to be changed to become objects, or can i convert the retrieved data into an object at the start of the test. Test method is below

/**
     * Test Getting Details by Importer and Year method
     *
     * @return void
     */
    public function testGetDetailsByImporterAndYear(): void
    {
        $expectedImporterDetail = $this->getFixtureData('ImporterDetails', 0);
        $importer = $this->getFixtureData('Importers', 0);

        $year = 2021;
        $result = $this->ImporterDetails->getDetailsByImporterAndYear($importer['id'], $year);
        $this->assertEquals($expectedImporterDetail, $result, 'Should only be one result');

        $expectedResult = null;
        $importerId = PHP_INT_MAX;
        $yearMax = 2038;
        $result = $this->ImporterDetails->getDetailsByImporterAndYear($importerId, $yearMax);
        $this->assertSame($expectedResult, $result, 'Should be no result returned');
    }

and an example of the test data

        $data = [
            [
                'id' => '1',
                'client_id' => '1',
                'importer_id' => '1',
                'name' => 'Ethil Jones',
                'email' => '[email protected]',
                'address' => '136 Manor Way
Great Marton
FY3 7UT',
                'year' => '2021',
                'created' => '2021-12-07 22:32:59',
                'modified' => '2021-12-07 22:32:59',
            ],

Ive looked into mock objects, though not sure that would be the right use case here. Any pointers would be great. Bottom half of the test works, as the method may return null. Just the part where the object is returned struggling to assert same

How to fetch list of all the product item from tally server using php

I have to fetch product item list from the paritcular table list
from the tally server using php code.So in my tally server i have
the few tables like stock item,stock groups,stock category in my
inventory master.In my stock item table i have approx more than
3000 items in the list with product details,for this i have also
got the php code using curl method but that list is not coming
from stock item table it is coming from somewhere else.Please help
me how i can achieve this.

<?php

$res_str =<<<XML
 <ENVELOPE>
 <HEADER>
 <TALLYREQUEST>Export Data</TALLYREQUEST>
 </HEADER>
 <BODY>
 <EXPORTDATA>
 <REQUESTDESC>
 <REPORTNAME>stock category summary</REPORTNAME>
 </REQUESTDESC>
 </EXPORTDATA>
 </BODY>
 </ENVELOPE>
XML;


$url = "http://localhost:9000/";

        //setting the curl parameters.
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
        curl_setopt($ch, CURLOPT_POSTFIELDS,
                    "xmlRequest=" . $res_str);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
        $data = curl_exec($ch);
        //echo '<pre>';
        //var_dump($data);die;

        curl_close($ch);
        // get the xml object 
    $object = simplexml_load_string( $data );
    
    echo "<pre>";
    print_r($object);die;
    
?>

Display posts from multiple categories in WordPress

We have a WordPress site with two categories like

Category A – 500 posts

Category B – 320 Posts

We created a new category C and displayed the articles from category A. We tagged 200 articles in the A category and we want to show them like this:

Category A – 300 Post (500-200)

Category B – 320 Post

Category C – 200 Post (200 tagged artile)

Category C home page is working fine (Archive page by custom WP query) but pagination pages going to 404

Category C does not assign any articles I want to display articles from category B as only tagged articles.