Laravel auto-injection issue (Too few arguments) after migrating to PHP 8.2

I recently migrated my Laravel project to PHP 8.1, and I’m encountering an issue with dependency injection in my controllers. I have set up auto-injection in my AppServiceProvider using the bind method, but I’m getting a “Too few arguments” error in my controller methods.

Here’s the relevant part of my AppServiceProvider:

use AppRepositoriesTenantRepository;
use AppRepositoriesAdministrationRepository;
use AppRepositoriesTenantRepositoryInterface;
use AppRepositoriesAdministrationRepositoryInterface;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind(TenantRepositoryInterface::class, TenantRepository::class);
        $this->app->bind(AdministrationRepositoryInterface::class, AdministrationRepository::class);
    }
}

And here’s a sample controller method:

use AppRepositoriesTenantRepositoryInterface;
use AppRepositoriesAdministrationRepositoryInterface;

class [ControllerName] extends Controller
{
    public function tenantListe($message = "", $niveauMessage = "", TenantRepositoryInterface $interface)
    {
        // Method implementation...
    }

    // Other controller methods...
}

I have multiple controller methods, each using a different repository interface. Before the migration, this setup was working fine.

How can I resolve this “Too few arguments” error and properly set up dependency injection in my Laravel controller methods after migrating to PHP 8.1?

After encountering the “Too few arguments” issue in my Laravel controllers post-migration to PHP 8.1, I tried reorganizing the parameters by placing TenantRepositoryInterface $interface as the first parameter in the method signature. For example:

public function tenantListe(TenantRepositoryInterface $interface, $message = "", $niveauMessage = "")

This adjustment resolved the problem for this specific method. However, considering the large number of methods in my project, manually reorganizing each method is not a scalable solution.

Is there a more efficient and automated way to address this issue across all my controller methods, considering the recent migration to PHP 8.1?

Could not resolve host from Curl PHP but not from Postman. Why?

I send a PHP Curl request and get the message: Could not resolve host.

The only thing from all of the variety answers that could help me is writing “IP => host” into the /etc/hosts (referring to https://stackoverflow.com/a/56580719/6104996). Only then I can get data from URL

Meanwhile, if I send the request with Postman, I can get the data even if didn’t write anything in /etc/hosts.

Why? How do I see is the actual request from Postman to copy it in my code? I don’t want to write anything in the /etc/hosts


P.S. if I click “Code” -> “PHP – cURL” and copy paste it to my code, it returns me “Could not resolve host” anyway

enter image description here

mysqldump does not work in subdomain directory

I write a code that dump a mysql database into sql file and then compress it. It works fine when it runs in public_html directory in cpanel. But I have a subdomain and it has seperate directory like v2.saadapp.ir and my php script in that folder does not work and even do not get any error message.

`

here is my code

`include 'key.php';
$fileName='backups/db_backup4_'.date('Y-m-d_H-i-s').'.sql';

  $cmd='/usr/bin/mysqldump --user='.$dbuser.' --password="'.$dbpass .'" --host=localhost '.$dbname.' > '.$fileName .'  2>&1';

//var_dump($cmd);exit;

exec($cmd, $output, $return);

if ($return != 0) { //0 is ok
var_dump($result);
echo "<br />";
var_dump($output);
echo "<br />";

    die('Error: ' . implode("rn", $output));

}

function mkZip($inputfile){

    // echo '<br>'.$inputfile;

$zip = new ZipArchive;

$res = $zip->open('backups/bkup_'.date('Y-m-d_H-i-s').'.zip', ZipArchive::CREATE);

if ($res === TRUE) {

    $fileContent=file_get_contents($inputfile);

    $zip->addFromString($inputfile, $fileContent);

    $zip->setEncryptionName($inputfile, ZipArchive::EM_AES_256, 'passw0rd');

    $zip->close();

    echo $inputfile.' ok';

    unlink($inputfile);

} else {

    echo 'failed';

}

}



mkZip($fileName);

Rundeck Job Not Stopping Execution Properly

I have a Rundeck job that performs a data archival task. The job executes successfully, but when I try to kill the job from the Rundeck UI, it seems to keep inserting records until all the data is moved to the archive table.

Note I am using php script to move the DB records into archive table.

here are the rundeck job logs:

query, job_273::moveRecords, 1.7757458686829, DANGER
12:00:32            **** job_273::moveRecords time taken 1.8048849105835 sec, offset: 6000 
12:00:32            
12:00:32            **** Job 273:: Success, data archived successfully!!
12:00:32            
12:00:35            query, job_273::moveRecords, 1.5157968997955, DANGER
12:00:35            **** job_273::moveRecords time taken 1.5820739269257 sec, offset: 7000 
12:00:35            
12:00:35            **** Job 273:: Success, data archived successfully!!
12:00:35            
12:00:39            query, job_273::moveRecords, 1.6569089889526, DANGER
12:00:39            **** job_273::moveRecords time taken 1.689309835434 sec, offset: 8000 
12:00:39            
12:00:39            **** Job 273:: Success, data archived successfully!!


**** Job 290:: Success, data archived successfully!!

12:00:39            
12:00:43            Result: 2147483647
12:00:43            Failed: NonZeroResultCode: Result code was 2147483647
12:00:43            java.util.concurrent.CancellationException
12:00:43                at java.util.concurrent.FutureTask.report(FutureTask.java:121)
12:00:43                at java.util.concurrent.FutureTask.get(FutureTask.java:192)
12:00:43                at com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly(Uninterruptibles.java:135)
12:00:43                at com.google.common.util.concurrent.Futures$4.run(Futures.java:1158)
12:00:43                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
12:00:43                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
12:00:43                at java.lang.Thread.run(Thread.java:750)
12:00:43            Cancellation while running step [1]
12:00:43            Execution failed: 4503990 in project BIM_QA: [Workflow result: , step failures: {1=Interrupted: Cancellation while running step [1]}, flow control: Continue, status: failed]

Despite this, the job continues until completion.

Here are some details:

Rundeck version: [2.10.7-1]

Has anyone encountered a similar problem, and what steps can I take to ensure that killing the job stops the execution immediately?

Any insights or suggestions would be greatly appreciated. Thank you!

my code work on the localhost but doesn’t work on the public host

I have a code that I tested with localhost, it works, but it doesn’t work on the host. I tried several services, none of them worked. If possible, tell me where the problem is.
here is my code:

<form action="" method="post">
<textarea name="h"> text box</textarea><input type="submit">

</form>

<?php
$h=$_POST["h"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');

curl_setopt($ch, CURLOPT_HTTPHEADER, [

    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',

    'Accept-Language: fa-IR,fa;q=0.9,en-US;q=0.8,en;q=0.7',

    'Cache-Control: max-age=0',

    'Connection: keep-alive',

    'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryhdhdjjddjd726',

    'Origin: https://example.ir',

    'Referer: https://example.ir/admin/41373153',

    'Sec-Fetch-Dest: document',

    'Sec-Fetch-Mode: navigate',

    'Sec-Fetch-Site: same-origin',

    'Sec-Fetch-User: ?1',

    'Upgrade-Insecure-Requests: 1',

    'User-Agent: Mozilla/5.0 (Linux; Android 9; Redmi 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36',

    'sec-ch-ua: "Not:A-Brand";v="99", "Chromium";v="112"',

    'sec-ch-ua-mobile: ?1',

    'sec-ch-ua-platform: "Android"',

    'Accept-Encoding: gzip',

]);
curl_setopt($ch, CURLOPT_COOKIE, 'SESSIONID=mysession');
curl_setopt($ch, CURLOPT_POSTFIELDS, "------WebKitFormBoundaryhsjsksksk82728jJsjsjrnContent-Disposition: form-data; name="___TOKEN_FORM___"rnrJsjsjsjdjdjjdz837373jxjxrn------WebKitFormBoundaryhshsjssj8272jzjJrnContent-Disposition: form-data; name="title"rnrnmsgrn------WebKitFormBoundarymdudjdjdjrnContent-Disposition: form-data; name="text"rnrn".$h."rn------WebKitFormBoundaryyesjdjd737rnContent-Disposition: form-data; name="datetimeSend"rnrn۱۴۰۲/۰۵/۰۳ ۰۸:۵۱:٠٠rn------ddgdddhrnContent-Disposition: form-data; name="state"rnrnsendingrn------WebKitFormBoundaryjzjzjzjz837JjdrnContent-Disposition: form-data; name="m_dateTimeDelete"rnrnrn------WebKitFormBoundaryhxhdjdjhdh7rnContent-Disposition: form-data; name="d_dateTimeDelete"rnrnrn------udjdjjdjdjdjdrnContent-Disposition: form-data; name="h_dateTimeDelete"rnrnrn------jdjdjdjdjdjdrnContent-Disposition: form-data; name="i_dateTimeDelete"rnrnrn------usussududuudrnContent-Disposition: form-data; name="viewCountForDelete"rnrnrn------uuuddjjd83837j--rn");
$rrj = curl_exec($ch);
print_r($rrj);
curl_close($ch);

I tested with localhost, it works, but it doesn’t work on the host. I tried several services, none of them worked. If possible, tell me where the problem is?
help me please

Pulling the “ID” to the Session when the Button in the Table is Clicked

enter image description here

When I click on the button, I want to transfer the ID information from the database to SESSION. But I want to do this without revealing ID information in any way. GET-POST exposes data, so I want to use SESSION.

<?php 

include "config.php";

    if (isset($_POST['update'])) {

        $firstname = $_POST['firstname'];

        $user_id = $_POST['user_id'];

        $lastname = $_POST['lastname'];

        $email = $_POST['email'];

        $password = $_POST['password'];

        $gender = $_POST['gender']; 

        $sql = "UPDATE `users` SET `firstname`='$firstname',`lastname`='$lastname',`email`='$email',`password`='$password',`gender`='$gender' WHERE `id`='$user_id'"; 

        $result = $conn->query($sql); 

        if ($result == TRUE) {

            echo "Record updated successfully.";

        }else{

            echo "Error:" . $sql . "<br>" . $conn->error;

        }

    } 

if (isset($_GET['id'])) {

    $user_id = $_GET['id']; 

    $sql = "SELECT * FROM `users` WHERE `id`='$user_id'";

    $result = $conn->query($sql); 

    if ($result->num_rows > 0) {        

        while ($row = $result->fetch_assoc()) {

            $first_name = $row['firstname'];

            $lastname = $row['lastname'];

            $email = $row['email'];

            $password  = $row['password'];

            $gender = $row['gender'];

            $id = $row['id'];            

        } 

    ?>

        <h2>User Update Form</h2>

        <form action="" method="post">

          <fieldset>

            <legend>Personal information:</legend>

            First name:<br>

            <input type="text" name="firstname" value="<?php echo $first_name; ?>">

            <input type="hidden" name="user_id" value="<?php echo $id; ?>">

            <br>

            Last name:<br>

            <input type="text" name="lastname" value="<?php echo $lastname; ?>">

            <br>

            Email:<br>

            <input type="email" name="email" value="<?php echo $email; ?>">

            <br>

            Password:<br>

            <input type="password" name="password" value="<?php echo $password; ?>">

            <br>

            Gender:<br>

            <input type="radio" name="gender" value="Male" <?php if($gender == 'Male'){ echo "checked";} ?> >Male

            <input type="radio" name="gender" value="Female" <?php if($gender == 'Female'){ echo "checked";} ?>>Female

            <br><br>

            <input type="submit" value="Update" name="update">

          </fieldset>

        </form> 

        </body>

        </html>       

    <?php

    } else{ 

        header('Location: view.php');

    } 

}

?> 

In short, I want to store the “ID” from the database on the server side.

php + .htaccess issue when rewriting urls for pretty permalinks

I’m trying to make a very simple small app in php: it is a small caption system for a museum. The structure is an so an index.php file that sends requests via querystring to a details.php page where I can read the single caption.

I’ll preface this by saying that I know little about servers and routing so I’m definitely missing something simple.I’ve tried watching every tutorial imaginable but I can’t figure out what’s not working.

I am developing locally on MAMP: basic rewrites are working but my solution doesn’t.

This is the markup for the index:

<!DOCTYPE html>
<html lang="en">

<?php include('includes/header.php'); ?>

<?php foreach($didas as $dida):  ?>

    <h3><?php echo htmlspecialchars($dida['title']); ?></h3>

    <a href = "details/details.php?url=<?php echo($dida['url']) ?>" >link</a>;

<?php endforeach ?>

<?php include('includes/footer.php'); ?>

</html>

The database is a table with 4 columns in mySql. one these columns is the url parameter which ideally becomes the querystring that calls the caption to me.

The url with the querystring is something like this:

http://localhost:8888/dida/details/details.php?url=test-1

and I am trying to rewrite it like this:

http://localhost:8888/dida/details/test-1

And here is my problem:

I tried to change this url with .htaccess: I followed a lot of different tutorials and answers here on stackoverflow

This is my Htaccess code


RewriteEngine On

# this rule rewrites my url but it gives me a 404 error

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^url=([w/-]*)
RewriteRule ^details/details.php$ /dida/details/%1 [QSD,R=302,L]

insert query don’t work after upload file to server cpanle [duplicate]

the query of insert data work correctly locally but after uploaded to server the query return false without waring or error message

$name = mysqli_real_escape_string($conn, $_REQUEST['name']);
$flag = 1;    
$stmt = $conn->prepare("INSERT INTO user_tab (name,flag) 
        VALUES(?,?)");
  $stmt->bind_param('si', $name,$flag);
  if($stmt->execute()){
      echo ' yes';
      
  }
  else{
      echo ' no ';
  }

before upload to server the result of echo is ‘yes’ .. after the upload return ‘no’

CodeIgniter -> Shopify API. How to log in via OAuth via the CLI? Using shopify-api-php

I have been racking my brain for ages here – if somebody could enlighten me I would be extremely grateful.

I’m trying to perform a standard OAUTH login, exactly as per the docs here:

https://github.com/Shopify/shopify-api-php

I have the api key, api secret key, host name etc. I am invoking the action using the command line – there is no web interface. I am running the application locally and using Session storage as there are no web cookies as I am not using a web browser.

Where I’m tripping up is on the ‘callback’ function – this doesn’t seem to do anything. I am calling Context::initialize and OAuth::begin(... without issue but that is where things trip up.

I have a corresponding route set up ‘/auth/callback’ which I believe should be invoked once the server returns a response to the initial login request which then provides the code, hmac values etc. needed to validate the session, but nothing happens.

I need to call OAuth::callback(... from within this callback function.

    Context::initialize(
        apiKey: config('ShopifyConfig')->api_key,
        apiSecretKey: config('ShopifyConfig')->api_secret_key,
        scopes: config('ShopifyConfig')->api_scopes,
        hostName: config('ShopifyConfig')->host_name,
        sessionStorage: new FileSessionStorage(),
        apiVersion: config('ShopifyConfig')->api_version,
    );

    $redirectUrl = OAuth::begin(
        shop: config('ShopifyConfig')->host_name,
        redirectPath: '/auth/callback', // doesn't do anything!
        isOnline: false,
        setCookieFunction: function (OAuthCookie $cookie) {
            $_SESSION['cookie'][] = [
                'name' => $cookie->getName(),
                'value' => $cookie->getValue(),
                'expire' => $cookie->getExpire(),
                'secure' => $cookie->isSecure(),
                'httpOnly' => $cookie->isHttpOnly(),
            ];
            return true;
        }
    );


public function logIn(Request $request)
{
    OAuth::callback(...)

    // Routes file

    $routes->get('/auth/callback', 'Home::logIn');
    $routes->post('/auth/callback', 'Home::logIn');
    $routes->cli('/auth/callback', 'Home::logIn');

Display Post if ACF Page Link Matches Current Page

I’m setting up a system to show customer reviews on a WordPress site. We have 6 service pages and I want to be able to choose when creating the review which of the service pages it shows on. I only want one random review that matches the relevant page to show each time.

I’ve created a custom post type (‘review’), added fields for review text, reviewer name, etc. I’ve also added an ACF Page Link field which allows me to choose the page or pages I want the review to show on. This is where I’m a bit stuck. I basically want the query to only get posts that match the Page Link selection. I can make it do the comparison later during the loop quite easily, but I can’t work out how to set the arguments to filter down in this way.

This is what I currently have:

global $post;
    $args = array(  
    'post_type' => 'review',
    'post_status' => 'publish',
    'posts_per_page' => 1,
    'orderby' => 'rand',
        );
        
$loop = new WP_Query($args);
    
    if ( $loop->have_posts() ) {
        
        echo '<div class="review-block">';
    
        while ( $loop->have_posts() ) : $loop->the_post(); 
        
            $page_to_display_on = get_field ('page_to_display_on');
            $reviewer_name = get_field ('reviewer_name');
            $service_supplied = get_field ('service_supplied');
            $reviewer_image = get_field ('reviewer_image');
            $review_text = get_field ('review_text');
            $review_stars = get_field ('review_stars');

echo $current_url;
            echo '<div class="review-image">';
            if ( $reviewer_image ) {
                echo '<img class="review-image-circle" src="' . $reviewer_image . '" />';
            }
            else {
                echo '<img class="review-image-circle" src="' . get_stylesheet_directory_uri() . '/images/google-reviews-icon.png" />';
            }
            echo '</div>';
            echo '<div class="review-content">';
            echo '<p>' . $review_text . '</p>';
            echo '<p class="review-name">' . $reviewer_name . ' - ' . $service_supplied . '</p>';
           
            for($x=1;$x<=$review_stars;$x++) {
                echo '<i class="fa fa-star" aria-hidden="true"></i>';
            }
            if (strpos($review_stars,'.')) {
                echo '<i class="fa fa-star-half-o" aria-hidden="true"></i>';
                $x++;
            }
            while ($x<=5) {
                echo '<i class="fa fa-star-o" aria-hidden="true"></i>';
                $x++;
            }
            

            echo '</div>';
           

        endwhile;
        echo '</div>';

}

wp_reset_postdata();

Is there a way to do a relationship query with an ACF custom field? Would I be better using a ‘Post Object’ field in ACF, which can return the post ID instead?

SCORM Integration using laravel

unable to acquire lms api content may not play properly and results may not be recorded

can you please help me to fix this issue

im using laravel framework and my scorm files im my project directory

solution for above problem

Local Setup not running up Laravel [closed]

Hi I was trying to run my local setup for php laravel. I have followed all the steps and php artisan serve command is also working correctly but still my website is not getting rendered on frontend. What to do ?

php artisan serve

Laravel development starting http://localhost:8000

PHP JSON Data Retrieval Query

I wonder if someone could avise where I am going wrong.

Using PHP the following code is being used successfully to fetched the JSON array from an external source:

$jsonData   = file_get_contents($link);

… following which the retrieved data appears to have also been successfully re-built and converted into a PHP array using the following code:

array_push($AllTable1, array(

    "bookingid"  => $bookingid2,
    "dayname"    => $dayname6,
    "daydate"    => $daydate4,
    "monthname"  => $monthname,
    "starttime"  => $starttime4,
    "title"      => $title7,
    "room"       => $room7,
    "roomcol"    => $roomcol,
    "roomcol2"   => $roomcol2

));

When the following code is run:

$AllTable1 = str_replace(PHP_EOL, '', $AllTable1);
echo json_encode($AllTable1, JSON_PRETTY_PRINT);

… data in the following format is successfully returned without any associated errors:

0   
    bookingid   "window.open('https://<pathtobooking>')"
    dayname "Mon"
    daydate "04"
    monthname   "December"
    starttime   "10:30"
    title   "Yoga Classes"
    room    "Large Hall"
    roomcol "#b30c35"
    roomcol2    ""
1   
    bookingid   "window.open('https://<pathtobooking>')"
    dayname "Mon"
    daydate "04"
    monthname   "December"
    starttime   "19:00"
    title   "History Group"
    room    "Small Hall"
    roomcol "#428bca"
    roomcol2    ""
2   
    bookingid   "window.open('https://<pathtobooking>')"
    dayname "Tue"
    daydate "05"
    monthname   "December"
    starttime   "10:00"
    title   "All Welcome Coffee Morning"
    room    "Kitchen,Small Hall"
    roomcol "#41753f"
    roomcol2    "#428bca"
3   
    bookingid   "window.open('https://<pathtobooking>')"
    dayname "Tue"
    daydate "05"
    monthname   "December"
    starttime   "20:30"
    title   "Table Tennis Club"
    room    "Large Hall"
    roomcol "#b30c35"
    roomcol2    ""
4   
    ... etc,etc

However, when the following code is run:

print_r($AllTable1);

… the following error is returned along with the array data:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Array
(
    [0] => Array
        (
            [bookingid] => window.open('https://<pathtobooking>')
            [dayname] => Mon
            [daydate] => 04
            [monthname] => December
            [starttime] => 10:30
            [title] => Yoga Classes
            [room] => Large Hall
            [roomcol] => #b30c35
            [roomcol2] => 
        )

    [1] => Array
        (
            [bookingid] => window.open('https://<pathtobooking>')
            [dayname] => Mon
            [daydate] => 04
            [monthname] => December
            [starttime] => 19:00
            [title] => History Group
            [room] => Small Hall
            [roomcol] => #428bca
            [roomcol2] => 
        )

    [2] => Array
        (
            [bookingid] => window.open('https://<pathtobooking>')
            [dayname] => Tue
            [daydate] => 05
            [monthname] => December
            [starttime] => 10:00
            [title] => All Welcome Coffee Morning
            [room] => Kitchen,Small Hall
            [roomcol] => #41753f
            [roomcol2] => #428bca
        )

    [3] => Array
        (
            [bookingid] => window.open('https://<pathtobooking>')
            [dayname] => Tue
            [daydate] => 05
            [monthname] => December
            [starttime] => 20:30
            [title] => Table Tennis Club
            [room] => Large Hall
            [roomcol] => #b30c35
            [roomcol2] => 
        )

    [4] => Array
        ... etc,etc

Also, wheneer the following code is run to attempt to output data from the array, for example:

$ddata = json_encode($AllTable1, true);
echo("The day of the sixth booking in the list is: n");
echo $ddata[5]['dayname'];

… the following error and output is returned (There are more than six sets of data in the array, btw.):

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

The day of the sixth booking in the list is: 

Effectively, the error remains and no data is returned.

Is it possibly that the data is not correctly formatted? If so, I cannot see why as the array data appears to be returned correctly in both the above array examples provided, despite the JSON error.

I’d be very grateful if anyone could assist and advise what is being done wrong and what needs to be done to resolve the issue.