How to dd multiple variables in Laravel ?

In this tutorial, I will give you an example of “How to dd (dump and die) multiple variables in Laravel”, So you can easily apply it with your laravel 5, laravel 6, laravel 7, and laravel 8 application.

Use of dd() in Laravel?

DD is a helper function that is used to dump a variable’s contents to the browser and stop further script execution. It stands for Dump and Die in Laravel application.

First, what we’re doing here, This is the example :

dump and die multiple variables in laravel

We are using 3 different tables with some dummy data which are integrated with 3 different models in our application.

Tables :

  • categories
  • subcategories
  • products
category table

subcategory table

product table

Models :

  • Category
  • Subcategory
  • Product

routes\web.php

 #dd multiple variables Example
 Route::get('/dd-multiple-variables','TestController@ddmultiplevariables');

App\Http\Controllers \TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Model\Category;
use App\Model\Subcategory;
use App\Model\Product;


class TestController extends Controller
{

  public function ddmultiplevariables()
  {
    $category = Category::all();
    $subcategory = Subcategory::all();
    $products = Product::all();
    dd($category,$subcategory,$products);
  }
}

Syntax :

dd($variable1,$variable2,$variable3);

Now, you can see the output in the browser, we have successfully dump and die multiple variables using single dd helper in Laravel”.

dump and die multiple variables in laravel output

In this article, we learned “How to use dd to dump and die multiple variables in Laravel”, I hope this article will help you with your application Project.

Read also: create a custom helper in Laravel 8.

Hi, My name is Gaurav Pandey. I'm a Laravel developer, owner of 8Bityard. I live in Uttarakhand - India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Javascript, JQuery, Laravel, WordPress. connect@8bityard.com

Scroll to Top