Laravel media library shows 403 error when trying to access media url

I am using the Media Library on a Laravel app locally and at the moment I am uploading the files in storage/app/public path. However when I am trying to access the file from the browser I am getting a 403 access forbidden error.

This error showed up after running the command php artisan storage:link, before that I was seeing a white screen when trying to open the image url on a new tab

// Livewire component
public function mount()
{
    $this->selectedImageUrl = $this->post->getFirstMediaUrl();
}

// blade component
<div class="space-y-4">
    <img src="{{ $selectedImageUrl }}" alt="" />
</div>

My function is not called a second time why [duplicate]

Here is my code for my simple function, below when I use echo and my function with a number greater than zero, the function returns true(1), when the number is less than zero, nothing happens, the code and the output of the program are attached

<?php
  function isPositive(int $number) : bool{
        return $number > 0;
    }

    echo "testn";
    echo isPositive(1);
    echo "testn";
    echo isPositive(-1);
    echo "testn";

output

I expected the is Positive(-1) function to return false (0)

PHP 8.2 execution time fatal error in WordPress

I’m having some trouble with a local wordpress setup where I’m working on an headless theme powered by vue.js

I’ve noticed that inside the debug.log file I will always get this error, it will be logged also for another WordPress file that is part of the CMS core files.

PHP Fatal error: Maximum execution time of 200 seconds exceeded in C:xampphtdocswordpresswp-includesclass-wp-dependencies.php on line 289 site:wordpress.org

At the moment this is the only theme where I’m having this kind of problem, I have other headless themes and they will load without problems. I’ve tried to create a new theme and included all the files but the result will be the same.

Is there a solution to fix this problem? I’m on the latest XAMPP version that will run php 8.2 but not sure if the problem is caused from this and I need to downgrade the XAMPP version to use a php 7.4 version.

laravel login refresh page

My laravel project doesn`t working on the hosting.But everything works perfectly on the local server(

When i switch to mysite.com, the index page “login” and enter the data in login form, tpage just refreshed

At the same time, if I go to mysite.com/register, I will be able to register a new user and write this data to the Users table in my database

I try make routes for test

Route::get('/test', function(){
  return User::All();

//this returned all users in DB(ill check connection with my DB)

});
Route::get('/test', function(){
  $user = Auth::user();
 print_r($user);

//this returned NULL

});

I understand the Auth::login function writes the authenticated user to a session and fills the memoer_token field into the database in the user table. In the table itself token is written, but in the session nothing is written.

But idk how to fix it, if it`s true

How can I run curl ssh line with php?

how can run this curl via guzzle or php curl? thank you

curl https://api.paylike.io/transactions/63e8bab91ec6fb693b2013ca/captures -u :84410d08-f822-43ab-8f09-a96ae0325bd8 -d currency=USD -d amount=4000

need run this curl in php or guzzle to confirm payment.

how do i customize woocommerce empty cart message

I’ve tried editing the empty cart message, but the changes made does not seem to show on the front end.

From the usual text “No products in the cart.” to “Oops! Looks like your cart is empty.” I’ve also tried the code provided by numerous other similar questions asked, but none seem to work either.

I tried using the following code in the mini-cart.php file;

<p class="woocommerce-mini-cart__empty-message"><?php esc_html_e( 'Oops! Looks like your cart is empty.', 'woocommerce' ); ?></p>

and also tried using the following code in the functions.php file;

add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
  global $woocommerce;

    if ( isset( $_GET['empty-cart'] ) ) {
        $woocommerce->cart->empty_cart(); 
    }
}
add_action( 'woocommerce_widget_shopping_cart_buttons', 'add_clear_cart_button', 10, 2 );
function add_clear_cart_button() {
    ?>
    <a class="button" href="<?php echo $woocommerce->cart->get_cart_url(); ?>?empty-cart"><?php _e( 'Empty Cart', 'woocommerce' ); ?></a>
    <?php
} 

how to automatically add input field when a value entered and the cursor also focus newly created input field

i completed dynamically add row function but i want to, when a value exit the input field the button automatically add another row and the cursor also focus newly added row. i want to implement this functionalyty in my code for my php codignater project

my inputfield code

 <div style="height:200px;width:1200px;border:2px solid #ccc;overflow:auto;">
     <table id="rf_id">
         <div class="form-group row col-sm-5" id="rf">
             <tbody id="rf123">
                 <tr>
                     <td> </td>
                     <td> <input type="text" placeholder="Enter product RFID code"
                             id="rfid" class="form-control" name="rfid[]"></td>

                     <td> <i class="fa fa-trash-o delete_rfid"
                             style="font-size:25px;color:red"
                             onclick="removeOptionRow('0');"></i>
                         <i class="fa fa-plus-circle tr_rfid_add" id="tr_rfid_add"
                             style="font-size:25px;color:green" aria-hidden="true"
                             onclick="addFilterOptionRow();"></i>
                     </td>
                 </tr>
             </tbody>
         </div>
     </table>
 </div>


 <div class="form-group row">

     <div class="col-sm-4">
         <input type="submit" id="assign_save" class="btn btn-success margin-bottom"
             value="<?php echo $this->lang->line('save') ?>"
             data-loading-text="Adding...">

     </div>
 </div>

My input field image
my input field
when clicking plus icon this add another input field
dynamically add row function for this input field, its a working function.

$("#rfid").focus();

function removeOptionRow(filter_row) {
    $('#invrow' + filter_row).remove();

}
var filter_row = 1;

function addFilterOptionRow() {

    html = '<tr id="invrow' + filter_row + '">';
    html += '<td> </td>';
    html +=
        '<td><input type="text" placeholder="Enter product RFID code" id="rfid" class="form-control" id="option_name' +
        filter_row + '" name="rfid[]" ></td>';
    html += '<td> <i class="fa fa-trash-o delete_rfid" style="font-size:25px;color:red" onclick="removeOptionRow(' +
        filter_row + ');"></i>';
    html +=
        ' <i class="fa fa-plus-circle tr_rfid_add" onclick="addFilterOptionRow();" style="font-size:25px;color:green" aria-hidden="true"></i>';
    html += '</td>';
    //html+='</tr>';
    //html+='<td><a href="javascript:void(0);" onclick="removeOptionRow('+filter_row+');">Remove</a></td>';
    html += '</tr>';
    $('#rf123').append(html);
    filter_row++;
    //  $("#rfid").focus();
    return false

}

expected:
i want to automatically add row when the value exit ,eg: i enter ‘A’ input to the input field ,the add button automatically add another input field.i try followying code but add button automatically click after defined time without entering input.

$(document).ready(function(){
 $('#tr_rfid_add').click(function(){
    });
    if($('.#rfid').val()){
  // set time out 5 sec
     setTimeout(function(){
        $('#tr_rfid_add').trigger('click');
    }, 4000);
}
});

I hope someone will give a correct solution.
thank you

Undefined constant “XML_PI_NODE” symfony

My symfony-react project was working. But I wanted to switch to typescript. And made some changes. Then i cleaned my apt list. Made apt autoremove, autoclean, etc.

And when i completely switched from js to ts, i found that my api symfony won’t work.
I went for /_profiler, and got this error :

Undefined constant "XML_PI_NODE"

I already tried to “sudo apt install php8.2-xml”, but it still doesnt work.

I think it might be caused by my careless work with apt repo. And i can just reinstall my Ubuntu.) But I want to do this without kill everything.

Ubuntu: 20.04.5 LTS
PHP : 8.2.1
Symfony: 6.0.20

How to Create user unique id in php with higest percent of uniquness

I have tried to create a user unique id, will it be unique or give trouble in the future?Please help. There are two functions.Need your guidance as I am a beginner

First one

    private function generate_uuid() {
   return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
       mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
       mt_rand( 0, 0xffff ),
       mt_rand( 0, 0x0fff ) | 0x4000,
       mt_rand( 0, 0x3fff ) | 0x8000,
       mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
   );
}

Second One

private function generateCustomerID() {
    return sprintf('CUID%07d', mt_rand(1, 9999999));
}

Php count conditions inside loop

I have this array for example :

$array_test=array("gren","green","red","red","green","blue");

My idea is know inside loop number of elementos with the condition i want, the array for show it´s more complex and this is only example for understand i need, because try different ways with “count” and don´t show right this number in each case.

I try this :

foreach($array_test as $array_ts) {

if($array_ts=="green") { Count number of elements green /// }

if($array_ts=="red") { Count number of elements red /// }

if($array_ts=="blue") { Count number of elements blue /// }

}

Thank´s for the help, regards.

Does PHP garbage collection destroy objects with no reference?

I’m having a hard time finding clear information on PHP’s garbage collection as it relates to objects referencing other objects. Specifically, I’m trying to understand what happens when I have a chain of objects that reference each other, and I destroy or unset() the first object in the chain. Will PHP know to GC the remaining objects in the chain or do I have to destroy them all individually to prevent a memory leak?

For example, Say I have a class BinaryTree with a variable rootNode and a Node class that extends BinaryTree and has 3 variables, a parent Node, a leftChild Node, and a rightChild Node. The rootNode will be the Node with a parent that is null, but every other Node created will reference either the rootNode or a subsequent child Node before it as the parent and any Nodes after it as either leftChild or rightChild. The rootNode, therefore, is the only way to reference any of the child nodes.

If I unset() the rootNode, will all other Nodes remain in memory? Would I need to iterate through the entire tree unsetting each Node individually to prevent them from just existing without a way to reference them anymore, or will PHP know that those objects can no longer be referenced and GC them?

So far what I’m reading leads me to believe I would need to iterate the entire list of objects to destroy them individually, but I’m wondering if anyone has any experience with this and can offer some clarity. TIA.

laravel 8 auth::user collection from tables

I am new to laravel 8 and blade syntax.
I am working on a project where users (agents) can upload apartments.
i have agent table with corresponding model relationship

agent model

public function property()
    {
        return $this->hasMany(Property::class);
    }

property model


 public function agents()
    {
    return $this->belongsTo(Agent::class);

    }

I used breeze to build up my registration and login

i want when an agent is logged in, i will display in his dash board list of his properties.


@foreach($properties as $property)
                                @if(($loop->count) > 0)
                                <td class="py-3 px-2">
                                    <div class="inline-flex space-x-3 items-center">
                                        <span>{{$property->propertyId}}</span>
                                    </div>
                                </td>

                                <td class="py-3 px-2">{{$property->building}}</td>
                                <td class="py-3 px-2">{{$property->rent->name}}</td>
@else
You have not uploaded any apartment
@endif
@endforeach

but i get error “Undefined variable $properties”.

Meanwhile, {{ Auth::user()->othernames }} works fine.

AgentController

public function index()
    {
        return view ('dashboard', [
            'agent' => Agent::all(),
            'appointment'=>Appointment::all(),
            'property'=>Property::all(),
            'schedule'=>AgentSchedule::all()


        ]);
    }

propertyController

public function create()
    {

        
        return view('pages.uploadapartment', [
            'states'=> State::all(),
            'areas'=>Area::all(),
            'buildings'=>building::all(),
            'buildingtypes'=>BuildingType::all(),
            'rentpaymentmethods'=>rentpaymentmethod::all(),
            'flattypes'=>flattype::all(),
        ]);

    }

How to make phpcs find PHP8 errors in whole project directory?

I am inside my project directory that has various files/folders and some have PHP8 fatal errors I have found when using the website (e.g. Fatal error: Uncaught Error: Non-static method), I am using the following command which I am expecting to show PHP8 compatibility errors:

php ./vendor/bin/phpcs . --extensions=php --standard=PHPCompatibility --runtime-set testVersion 8.0

However this is just returning 2 warnings that are for files inside /vendor directory, it doesn’t seem to be finding the errors, I think this maybe because it’s only searching through the vendor directory as I am using ./vendor/bin/phpcs what do I need to do to make it search through all PHP files in my project directory?

Package php7.0-curl is not available, but is referred to by another package

I was following this tutorial to install nextcloud on my homeserver.
After installing the database software, I need to install the last component – PHP.
However, after running the commands displayed on the tutorial I run into some errors :

Package php7.0-common is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source

I already tried to find solutions but they seem outdated, that’s why I raise this new topic

Thank you very much for your help.

Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04

While browsing solutions, I have already ran some commands to fix the problem :
sudo add-apt-repository ppa:ondrej/php-7.0 sudo apt-get install software-properties-common -y sudo apt-get update sudo apt-cache search php7.0-curl
and sudo apt-get install php7.0-curl from here

Fraction cannot display in DOMPDF 0.8.xxx

I have problem when parse Fraction to DOMPDF.
I’ve changed the font-family to DejaVu Sans, Roboto, and Helvetica Neue, Helvetica but it doesn’t affect the resulting PDF

By DB:
HTML Entities => enter image description here => ⅐

Result PDF:

  • Use font-family ‘times’ => ‘?’
  • Use font-family ‘dejavu sans’ => (whitespace)
  • Use font-family ‘roboto’ => (square empty)

Help me, guys!

I change PdfGenerator.php, edit file HTML for generate to DOMPDF, Have used mbstring_encryption_encode, utf8_decode