• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

phpjqueryajaxlaravellaravel-5


PHP Snippet 1:

//...
$product  = json_decode($request->product, true);
//...

PHP Snippet 2:

 public function dopayment(Request $request) {

            $input = $request->all();

            $product = json_decode($request->product);


            foreach ($product as $single) {
                # code...

                print_r($single->name);
            }

           print_r($product);
            exit;
        }

PHP Snippet 3:

if (is_array($product ) || is_object($product ))
{
    foreach($product as $arrayItems){
      // Perform x.
    }
}

Related Snippets

Parameter is not sent to Laravel route in Ajax

array_key_exists(): The first argument should be either a string or an integer

Login if user is active using Laravel Breeze

401 Unauthorized only occurring on some pages in Laravel 8

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

Assets not referencing to public folder (Laravel)

How can I create a Download Page with post php method?

Debugging Stripe Webhook Event

best way to store error messages in Laravel (session or variable)

Attempt to read property "view" on null when sending password reset email

AJAX call fails with SyntaxError: Unexpected end of JSON input

Laravel implode array items to new lines

Respond with status code 401 on authentication failure using Laravel and Passport?

How to fix Call to undefined method AppModelsTableName::factory?

Laravel 5.1 Unknown database type enum requested

About Contact Privacy policy Terms and conditions