• 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

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

Laravel 5 session not persisting after user is logged in

Edit XML in HTML form and submit to self

Update Order custom Field value with WooCommerce REST API

"properties should not be accessed directly" issue during WooCommerce 3.0 checkout

php mysql + create a friend request system

Laravel print last executed SQL query with Query log

Is there a way to correctly use sanitize_text_field and wp_unslash that doesn't cause psalm to error with "expects string, possibly different type"

Populate Dynamic Dropdowns List in Codeigniter

Laravel 5.2: Unable to locate factory with name [default]

Submitting a form with ajax in Wordpress

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

Image upload not working through ajax Laravel

PHP: Print caught exception like Xdebug

Connecting an HTML webpage to a SQL Server

About Contact Privacy policy Terms and conditions