How to use new Dumpable Trait in Laravel 11?
Hi,
In this post, i will show you how to use new Dumpable Trait in laravel 11 framework.
The release of Laravel 11 is around the corner and it is packed with a lot of new features and improvements. Laravel 11 comes with a slimmer application skeleton. Laravel 11 introduce streamlined application structure, per-second rate limiting, health routing etc.
Laravel 11 introduces a dumpable trait, streamlining debugging processes. In this example, we will create Product model and use the Dumpable Trait on it. Then, you can easily debug it using dump() and dd() methods.
You can see the simple example code:
Let's create a Product.php model and use the Dumpable trait as shown below:
app/Models/Product.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Traits\Dumpable;
class Product extends Model
{
use Dumpable;
/**
* Write code on Method
*
* @return response()
*/
protected $fillable = [
'name', 'body', 'status'
];
}
Now, you can simply debug it in your controller like the code below:
app/Http/Controllers/ProductController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Product;
class ProductController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$products = Product::latest()->get();
$products->dd();
}
}
You can see the below output:
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Create and Use Enum in Laravel 11?
- How to Publish Config Files in Laravel 11?
- How to Create Interface in Laravel 11?
- How to Create Custom Class in Laravel 11?
- How to Publish the lang Folder in Laravel 11?
- What’s New in Laravel 11: New Features and Latest Updates
- How to Install Laravel 11 Application?
- Laravel Eloquent Order By Length Query Example
- Laravel Eloquent Find by Column Name Example
- Laravel Eloquent Select Single Column to Array Example
- Laravel Eloquent Model Custom Function Example
- Laravel Copy Record using Eloquent Replicate Example