Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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.
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 :
We are using 3 different tables with some dummy data which are integrated with 3 different models in our application.
Tables :
Models :
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”.
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.