• 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

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 255

How to make dot match newline characters using regular expressions

Why i get wrong output for html markdown?

How to remove from a multidimensional array all duplicate elements including the original?

Fatal error: Array callback has to contain indices 0 and 1

PHP contact form configuration [duplicate]

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

Reducing authentication calls on external API (Laravel 5.6)

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

Lumen - Postgresql setup - Composer

How to KeyBy where multiple items have the same key

printing all running session variable in laravel 5.1

PHP array, move keys and values to new array, but mix it up

Valet, Xdebug after reboot Big Sur not working

Handling expired token in Laravel

About Contact Privacy policy Terms and conditions