laraverl 10 jetstream and livewire problem

I am working on Laravel login system the versions which I am using are Laravel 10 Jetstream 4.1 and livewire 3.0 I have an error my registration form is completely workable but after the redirecting on dashboard the dropdown of profile is not working so I can’t understand that how could I logout my account .. the console give the uncaught syntax error : invalid or unexpected token on livewire.js file at line no 9212

i am searched some commands to reinstalling of npm packages that are
php artisan config:cache
php artisan route:cache
php artisan view:cache
after deleting node-modules folder and package-lock.json reinstall npm using the command
npm install
but same error occur on dashboard
i checked manually livewire.js file but there is no error on this file at the mentioned line

Laravel render function works, but when i click button it cannot find component

I have a livewire class and i can see that it’s working because it’s rendering both the value and the page. But when i click the button, it gives me an error. This is my file apphttplivewireactions.php


namespace AppHttpLivewire;

use LivewireComponent;

class Actions extends Component
{   
    public $value="hi";

    public function call()
    {
        $this->value = 'bye';
    }

    public function render()
    {
        return view('livewire.actions');
    }
}

This is my blade file under viewslivewire

<button wire:click="call">SUM</button>
{{$value}}
</div>

My page is rendering so when i got to 127.0.0.1:8000/action i see the page and the button.
enter image description hereThe value, but when i click the button for call. I get this
Unable to find component: [app.http.livewire.actions] on my page. Any idea how to fix?
enter image description here
enter image description here
enter image description here

enter image description here

Laravel Nova: Create filter for date and time

So Im trying to edit a filter that i have for nova resource i want that filter to filter on date and time right now its filtering only on time. Ive tried different thing so far the best option i found was here:https://nova.laravel.com/docs/customization/filters.html
The problem i have now is that whenever i try to change anything within this component that the command created nothing is reflected in the browser. Ive tried recompiling my assets and clearing the cache but nothing works. Does someone here know how to use this nova:custom-filter assets, or how to add time to a date filter if so please help!

I tied to use the custom filter but it doesnt display in the browser
ive also tried just using a custom filter component someone else made but that also didnt work

How to prefill Elementor Contact form with URL and user information?

I have a Woocommerce webshop with lots of product in it built with Elementor Pro. Now I want to create an Elementor contact form placed in a clickable popup what I can place to all of the product pages. Now here comes the tricky part. This popup meant to be a “Report Abuse” form what users can use to report various problems with that particular product. I want to create different fields in the form like: Name; Email; Problmes (with checkboxes) and URL. Question is, how can I get the form to automatically fill the “URL” field with the URL the user is currently at when clicking? Also I would like the “Email” and “Name” fields to be automatically filled in as well when the user is logged in. (These two fields should be left blank in case the reporter is a guest.)

Is there any kind of code snippet what I can use or do you have a suitable solution for this?

Thank you in advance.

I tried with Elementors dynamic fields but did not lead to a solution.

make dynamic url when upload a same name pdf file and show as a versions

I’m uploading files from admin panel, i have a input with link name and one with pdf name

if (empty($_FILES['timetable_pdf']['name'])) {
        $timetable_pdf = $_POST['old_timetable_pdf'];
    }else{
    $link = $_POST['link'];
    $file_name = $_FILES['timetable_pdf']['name'];
    $folderName = "../" . strtolower(preg_replace("/[^a-zA-Z0-9]/", "", $link)) . "en";
    if (!file_exists($folderName)) {
      mkdir($folderName);
    }
    $pdfFile = $_FILES['timetable_pdf']['name'];
    $pdfPath =  $folderName . '/' . $pdfFile;
   $timetable_pdf =  basename($file_name);
    move_uploaded_file($_FILES['timetable_pdf']['tmp_name'], $pdfPath);
   
  }

and the home page url like this

<a href="<?php if(!empty($row['timetable_pdf'])){echo $row['link'] . 'en/' . $row['timetable_pdf'];} ?>" target="_blank" >Download <?= $row['e_title'] ?> Timetable</a>

and preview is
https://hostname/icms23en/pdf_name.php

i want when i update the pdf file with the same name then its show the latest url with version like this

https://hostname/icms23en/pdf_name.php?v=1,
https://hostname/icms23en/pdf_name.php?v=2,
https://hostname/icms23en/pdf_name.php?v=3

whenver i update the pdf then it’s show the url like this and i als want to see others files to change ther url with write a diffrent version

I want to log the logs of a controller in a new log file

In Symfony 5.4, and by using monolog 3.8. I want to log the request handling of a specifique controller, in a new log file . for my case is citiesController
this my monolog config.

monolog:
    channels:
        - deprecation 
        - cities_controller

when@dev:
    monolog:
        handlers:
            main:
                type: stream
                path: "%kernel.logs_dir%/%kernel.environment%.log"
                level: debug
                channels: ["!event"]
            # uncomment to get logging in your browser
            # you may have to allow bigger header sizes in your Web server configuration
            #firephp:
            #    type: firephp
            #    level: info
            #chromephp:
            #    type: chromephp
            #    level: info
            cities_controller_log:
                type: stream
                path: "%kernel.logs_dir%/CitiesController.log"
                level: debug
                channels: ['cities_controller']
            console:
                type: console
                process_psr_3_messages: false
                channels: ["!event", "!doctrine", "!console"]
           

I expect to get the logs of the cities controller in a new file called citiesController.log
but as far as I check the log file doesn’t get created .
I get the logs in var/dev.logs

How to add a function with generator so that it selects certain strings php

I have a function with string output that outputs a sign in line 5. How to using a generator to add a function that will output line-by-line data from the first variable, where a new line is defined by sign; and the function should also have a limit – stop execution after output of 25 lines

<?php
function getRandomWord($len = 5) {
    $word = array_merge(range('a', 'z'), range('A', 'Z'));
    shuffle($word);
    return substr(implode($word), 0, $len);
}

$sign = ';';

for ($i = 0; $i < 100; $i++) {
    echo getRandomWord();
    if (($i + 1) % 5 == 0) {
        echo $sign;
    }
    echo "n";
}
?>

How to Use Passport in a Laravel CRUD app?

I’ve been learning Laravel on my own for the past couple of weeks and I’ve developed a simple vehicle registration application.

Now I want to add authentication via passport (OAuth2) to the application rather than sanctum.

Details of my Project

Laravel Breeze for Authentication
Blade
Simple CRUD app where users can register vehicles for service

I’ve scoured the internet so far and couldn’t find any up to date resources that could help me ( I’ve actually tried a lot of YouTube tutorials and none of them worked for me as they are very much older)

The most recent error I got from following a YouTube tutorial is this:
The GET method is not supported for route api/auth/login. Supported methods: POST.

This error occurs even when I tried POST method for the api route 🙁

I also tried the official passport documentation, but it is overwhelming 🙁

So now I’m looking for some resources on Passport or someone who can guide me through the authentication process

How to convert to number in PHP Spread Sheet

I have a PHP Spreadsheet code as follows

$cellAddress = 'Q' . $i_s1;
    $cell = $sheet->getCell($cellAddress);
    $style = $cell->getStyle();
    $style->getNumberFormat()->setFormatCode('_(* #.##0,00_);_(* (#.##0,00);_(* "-"??_);_(@_)');
    
    if($resolve_1_s1 == "" && $closed_1_s1 == ""){
        $sheet->setCellValue('Q'.$i_s1, "0");
    } else {
        $totalDuration_s1 = calculateDuration($inistatus_s1, $created_1_s1, $resolve_1_s1, $closed_1_s1, $tahun_mulai, $tahun_selesai);
        $hasilAkhir_s1 = number_format($totalDuration_s1, 2, ',', '.');
        $sheet->setCellValue('Q'.$i_s1, $hasilAkhir_s1);
    }

but when I open the file, it appears as follows

enter image description here

I want the warning to disappear (make it as Convert to Number)

enter image description here

Writing feature test for protected endpoints in Laravel 10 authenticated by Auth0

Situation:

I have a Laravel 10 app that uses was setup as ‘Regular web application’ in Auth0. I want to write feature test for protected routes but Im not sure how I perform authentication. I cant find documentation for this.

Detail of my setup

  • Laravel 10
  • Auth0 7.8

I followed https://auth0.com/docs/quickstart/webapp/laravel/interactive to setup laravel with auth0

  • I have ‘api/posts’ endpoint that only admins can access. Admin is defined in auth0 with permission.

At this point I need direction in this, Im new with auth0 integration.

Thank you so much in Advance.

Unit testing against protected properties [duplicate]

Ideas how to write good OOP code, SOLID, incapsulation, loose coupling and so lead to

  • not using public properties
  • use as little getters as possible

Say we have code

class Some
{
  protected int $x;
  protected int $y;
 
  public function __construct(int $x, int $y) {
    $this->x = $x;
    $this->y = $y;
  }

  public function swapXY() : void {
    $r = $this->x;
    $this->x = $this->y;
    $this->y = $r;
  }
}

Test will not work

class SomeTest extends PHPUnitFrameworkTestCase
{
    public function testSwap() {
        $obj = new Some(5, 6);
        $obj->swapXY();
        $this->assertSame(6, $obj->x);  // ERROR
        $this->assertSame(5, $obj->y);

        
    }
}

How can I test Some::swapXY() method with phpunit since phpunit 9.0 dropped support methods like assertAttributeSame() ?

I am not discussing here testing protected/private methods.
Only this situation: We send a signal to object via it’s method.
Post condition of this work is not some value returned, but some of object properties set to another values.

Using Reflection will help, but why it is considered like so bad idea that it was taken away from testing framework?
Thanks

Tried to solve with the ways recomended

Warning: Undefined variable $link (from mysql to mysqli)

i upgrade my code from mysql to mysqli.

I edit the mysql query line and now comes the error

Warning: Undefined variable $link
Fatal error: Uncaught TypeError: mysqli_query(): Argument #1 ($mysql) must be of type mysqli, null given**

function getSystemparameter($parameter) {
  $ergebnis = mysqli_query($link, "select wert from systemparameter where parameter='$parameter'");
  $zeile = mysqli_fetch_row($ergebnis);
  return $zeile[0];

My Database Connection:

function connectDatabase() {
  include('./serverConfig.php');
  $link = mysqli_connect($SQLURL, $SQLBenutzer, $SQLPasswort) or die ("Keine Verbindung !");
  if (!$link) {
    die('Could not connect: ' . mysqli_error());
  }
  mysqli_select_db($link,$DB) or die ("Kann DB nicht öffnen !");
  return $link;

Nothing idea for a solution.

I can’t run this php script in terminal in cPanel on linux

First time I’m trying to set a cron job on my website.
Before than that, I would like to try to run it in terminal.

In my cron jobs page I’ve found this command to run the script:
/usr/local/bin/php /home/functio1/public_html/path/to/cron/script

I’ve created a php file and I’ve changed the command above to point to the right directory.
The command apparently works as I don’t get any error, neither I don’t get any error file in the folder where the php file is located, but nothing happens.

This is the content of the php file:

<?php

include "../../../db/config.php";
include "../../../telegram/functions.php";

$query = "SELECT * FROM users WHERE DATE_FORMAT(user_birth_date,'%m-%d') = DATE_FORMAT(NOW(),'%m-%d')";
$result = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($result)){  
    $dateOfBirth = $row["user_birth_date"];
    $today = date("Y-m-d");
    $diff = date_diff(date_create($dateOfBirth), date_create($today));
    $age = $diff->format('%y');
    $birthdays = "Oggi è il compleanno di: " . $row["user_name"] . " " . $row["user_surname"] . " (" . $age . " anni)";
    sendMessage("max", $birthdays);
}

?>

I can say the code above works.
I’m using it at the moment by pressing a button on the website.
Basically it sends me messages on telegram for each user to help me to remember their birthdays.

I would like to be executed automatically once a day, but when I try to run the file using the command above nothing happens. What am I doing wrong?

Thanks for your help,

Max

Missing illegal Collation issues after upgrading mysql5.7 to mysql8.0.3*

SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8mb3_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,COERCIBLE) for operation '=', query was: SELECT mobile_users.* FROM mobile_users WHERE (first_name = 'John') AND (last_name = 'Rodríguez')

Getting above error when running a select query in php, Last_name is having special character so this issue occurs. but this was working fine in mysql5.7 and now after upgrade to mysql8.0 getting above exception.

How to fix this one without modifying existing production data’s in db. My DB structure is (SaaS) Client based dbs. So have many db’s which is created using mysql5.7.

proxy and php problem installing composer

I tried installing composer but I keep getting this error.
to note I am using a company laptop, so it has its own proxy which I added to the environment variables.

The Composer installer script was not successful [exit code 1].

Your proxy settings may be causing this error.

Script Output: The “https://getcomposer.org/versions” file could not
be downloaded: preg_split(): Passing null to parameter #3 ($limit) of
type int is deprecated php_network_getaddresses: getaddrinfo for
getcomposer.org failed: This is usually a temporary error during
hostname resolution and means that the local server did not receive a
response from an authoritative server. Failed to open stream:
php_network_getaddresses: getaddrinfo for getcomposer.org failed: This
is usually a temporary error during hostname resolution and means that
the local server did not receive a response from an authoritative
server