Clear rate limiter cache in Laravel

I’m trying to simply drop a key from the cache that RateLimiter saves.

// fail 1
Cache::forget($rateLimiterCacheKey); // false

// fail 2
Cache::getStore()->forget($rateLimiterCacheKey); // false

// fail 3
$cacheManager = app('cache');
$cacheManager->store()->forget($rateLimiterCacheKey); // false

// works:
Artisan::call('cache:forget', [$rateLimiterCacheKey]); // true (default `ForgetCommand.php` console command)

Is there anyone out there able to me how to clear the rate limiter cache without using artisan?

query does not work.You have an error in your SQL syntax [duplicate]

Query does not work.You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘WHERE vehicle_id = 2 and now() and status = 1 order by id desc limit 1’ at line 1

my code

html
<form action="update2.php" method="post">
  <p>
    <label align-text="center" for="real_goe"><h3>place you go <h3></label>
    <input type="text"  name="real_go" class="form-control">
  </p>
  <button type="submit" class="btn btn-success">save</button>
</form>

code php

$a = $_POST["real_go"];
$sql ="UPDATE test_car.New_car_car_reservation SET real_go =$a  WHERE vehicle_id = 2
and now()
and status = 1
order by id desc limit 1 ";
 
$query = mysqli_query($db,$sql);
if(!$query)
{
    echo "Query does not work.".mysqli_error($db);die;
}
else
{
echo "<script>alert('save')</script>";
echo "<script>window.location='index2.php'</script>";
}

Laravel 6 Unable to run artisan ui vie for new project

I’m busy setting up a new Laravel 6 Project (on Debian 10 with php8.0), which was all working fine.

cd /opt/laravel/

Install local composer to current directory /opt/laravel/

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Create the Laravel 6 Project

php composer.phar create-project --prefer-dist laravel/laravel testapp "6.*"

This seems to work fine, then install local composer for this project

cd /opt/laravel/testapp

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

But when I try to install laravel/ui

php composer.phar require laravel/ui --dev

I’m getting a big fat error

Using version ^3.4 for laravel/ui
./composer.json has been updated
Running composer update laravel/ui
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/ui[v3.4.0, ..., 3.x-dev] require illuminate/console ^8.42|^9.0 -> found illuminate/console[v8.42.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev] but these were not loaded, likely because it conflicts with another require.
    - Root composer.json requires laravel/ui ^3.4 -> satisfiable by laravel/ui[v3.4.0, ..., 3.x-dev].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require laravel/ui:*" to figure out if any version is installable, or "composer require laravel/ui:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Is there something in my set up causing this install to fail?

Show button in a site only if the page has a specific href

I try to show a button on a page, only if that page has a specific href.
Unfortunately, the code that i am using will show the button on all pages of the site instead of just /search/

<?php if (pathname == "https://www.example.com/search/") {?> <div class="spotlight"><h1><button type="button">Click Me!</button></h1></div><? } ?>

Can someone tell what i am doing wrong here?

Any php or jquery solution would be welcomed.

PHP Merger Array from Function’s Result

I have a function and the result is array. After print_r($result) here’s the array :

Array
(
    [0] => Array
        (
            [id_jabatan] => 3
            [keterangan_jabatan] => Direktur Utama
            [posisi] => Direktur
            [parent_id] => 0
        )
)
Array
(
    [0] => Array
        (
            [id_jabatan] => 4
            [keterangan_jabatan] => Direktur YMFK
            [posisi] => Direktur
            [parent_id] => 3
        )
)

The result from the function is 2 difference array. How to merge this all array into :

Array
(
    [0] => Array
        (
            [id_jabatan] => 3
            [keterangan_jabatan] => Direktur Utama
            [posisi] => Direktur
            [parent_id] => 0
        )
    [1] => Array
        (
            [id_jabatan] => 4
            [keterangan_jabatan] => Direktur YMFK
            [posisi] => Direktur
            [parent_id] => 3
        )
)

I have try array_merge but it didn’t work. Any suggest?

Http send post has no params

I have two app in Laravel. One is simple api with one controller if i send params using online tool or postman app everything is ok. i need check in headers to send ‘Host’ without this header i got error 400 Bad Request. But if i try send the same from my second laravel app i’ve got empty params request

$response = Http::asForm()->withHeaders([
    'Host' => 'example.com:8091',
])->post('http://example.com:8091/abc/test/', [
     'param_1' => 'abcdefgh123',
     'param2' => '+447707303095',
]);

$body = $response->getBody()->getContents();

I tried asForm() and nothing. What should be in Host header ?

Symfony: How to make variable work on every page?

I have a question for my Symfony project.

I have this code which shows the number of rows in a given database table:

// BudgetRepository
public function countBudgets()
{
  $qb = $this->createQueryBuilder('budget');
  return $qb
    ->select('count(budget.id)')
    ->getQuery()
    ->getSingleScalarResult();
}
// BudgetController
public function all(EntityManagerInterface $entityManager)
{
  $repository = $entityManager->getRepository(Budget::class);
  $count = $repository->countBudgets();
  return $this->render("budget/budget.html.twig", ['numberOfBudgets' => $count]);
}

It works, but it only works inside budget/budget.html.twig by usung {{ numberOfBudgets }}.

How can I make it work on every page (specifically I want it to be placed in my file called _sidebar.html.twig? Right now if I place {{ numberOfBudgets }} onto _sidebar.html.twig I get this error message “Variable “numberOfBudgets” does not exist”.

How should I rewrite the code?

Sql query with where conditions

I have table ‘zipcode’ and that have column ‘code’. Code column have staring of zipcode like

395
453
302
1203
12

I want to write sql query from that i can identify is this zip code match with records?

Valid Input zipcode

395004
395152
3952
1256

WooCommerce Security Update 402 -> 404 break site

Just wondering if anyone else has had this issue, our site is currently running 4.0.2 albeit an old version of WooCommerce, however, there was a security update over the weekend to remove Paypal standard from WooCommerce which forces an update to 4.0.4.

The site has tried to do this but it didn’t successfully complete the update and in turn break the site with the following error:

PHP Fatal error: Uncaught Error: Call to undefined function is_woocommerce()

To fix the issue we manually download 4.0.4 and over write the files, however, within a couple of hours we have the same issue again.

WordPress version: 5.7.5
WooCommerce Version: 4.0.4

Safe to call WooCommerce, WordPress and CoCart endpoints in frontend? I need your opinion

Question

I got a question about security. I am building a mobile webshop in Flutter. Is it bad to make those API calls in the frontend? Should I make a separate backend for it in Node for example?

I have also read that you can ‘create’ your own endpoints in WordPress with PHP. What about that? Does that make it any safer or not?

What endpoints do I use?

There is an existing WooCommerce API to retrieve products, get categories, create orders on the WooCommerce API. On the CoCart API, you can retrieve the cart, add to cart, delete cart, etc…

For the Mollie payment APIs, I think it is better to make a backend.

My take on it

I think it is fine to call those endpoints in the frontend. I have seen Flutter packages for WooCommerce to call those endpoints. Yes, I do send the basic auth in the headers… so I am not sure how ‘dangerous’ that is.

But on the other side. What can the ‘hacker’ do? They can see all the products, that is fine I guess. I am not sure if they can create orders… They cannot steal money at least 🙂

Reference code

For reference, here is a piece of code when calling an endpoint:

Future<Product> getProductById(int productId) async {
    String basicAuth =
        'Basic ' + base64Encode(utf8.encode('$username:$password'));
    print(basicAuth);

    var response = await http.get(
        Uri.parse(
            'https://websitename/wp-json/wc/v3/products/${productId}'),
        headers: <String, String>{'Authorization': basicAuth});
    if (response.statusCode == 200) {
      return Product.fromJson(jsonDecode(response.body));
    } else {
      throw Exception('Failed');
    }
  }

Let me know your opinion!

Hide woocommerce notice with checkbox based shipping on class

Want to hide woocommerce notice with jQuery on checkout page if specific shipping class checkbox is checked. Trying to make with this code but not working for me 🙁

//Hide Delivery Message in case Express Shipping Checked

add_action( 'woocommerce_checkout_process', 'hide_notice_billing' );
function hide_notice_billing(){
    ?>
        <script>
        jQuery(function($){
           $(document).ready(function() {
    $(document).on("click", "#shipping_method_0_flat_rate-12", function(e) {
       var checked = $(this).find("input:checkbox").is(":checked");
       if (checked) {
           $('.woocommerce-message').hide(300);
       } else {
           $('.woocommerce-message').show(300);
       }
    });
});
        });
    </script>
    <?php
}

Get data from WooCommerce object [duplicate]

I’m struggling to get specific data from wc_get_orders().

Here is the code:

$args   = array(
    'numberposts' => - 1,
    'orderby'     => 'date',
    'order'       => 'DESC',
    'customer_id' => get_current_user_id(),
);
$orders = wc_get_orders( $args );
echo '<pre>', var_dump( $orders ), '</pre>';

Here is the part of the object:

["meta_data":protected]=>
    array(4) {
      [0]=>
      object(WC_Meta_Data)#3544 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1135)
          ["key"]=>
          string(13) "is_vat_exempt"
          ["value"]=>
          string(2) "no"
        }
      }
      [1]=>
      object(WC_Meta_Data)#3545 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1136)
          ["key"]=>
          string(13) "tip_korisnika"
          ["value"]=>
          string(13) "Fizičko lice"
        }
      }
      [2]=>
      object(WC_Meta_Data)#3546 (2) {
        ["current_data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
        ["data":protected]=>
        array(3) {
          ["id"]=>
          int(1137)
          ["key"]=>
          string(12) "fs4e_methods"
          ["value"]=>
          string(5) "obuka"
        }
      }
      [3]=>

I’m trying to get the value of tip_korisinka, which is inside WC_Meta_Data that seems to be protected. Check this screenshot: https://prnt.sc/CI-UfqEkuuag

This is one of the solutions without success that I have tried so far:

foreach ( $orders as $key => $value ) {
    echo $key->$value['tip_korisnika'];
}

Any help would be appreciated.

How to get php database values before the page has loaded using javascript?

So i have 3 pages. upload.php, main.php and script.js. Upload.php lists some database entries, and has a button behind each entry for more info on the entry. When you press the button it gives the ID value from the database with POST in the url and so it loads the info in main.php with the given id.

So here is the problem, i have a javascript file: script.js which needs those db values. I watched a tutorial on passing a variable from php to js using ajax. But the problem is that the values on main are only posted when you press the button in upload.php. Which means when i run the script it immeadiatly goes to main.php and states that the values are empty. Which is true ofcourse.

How do i make the javascript get the values from main/ or database directly?

Im very new to js.

Optimize laravel eloquent query

hello there i am working on a project with 30000 records, i want to print all the records on the paper, but when excute the following command,it keeps on loading the data until it runs out of memory, keep in mind i am fetching data with three different tables using relations with user_id in common in all the tables, i want to optimize the query, so that i can print all the user records seamlessly

$users= AppUser::with(['withdarawals','deposits'])->get()->groupBy('id');
        dd($users);