Log an object in Laravel

In later versions of Laravel there is no need to use print_r() nor json_encode() in your log statements if you want to log an object.

Use the second parameter to pass an array. For example:


Log::info('My message', [$user]);

// The Output will be

[2021-08-17 09:23:13] local.INFO: My message [{"App\\Models\\User":{"name":"Rosalia Mraz Jr.","email":"[email protected]","email_verified_at":"2021-08-17T07:23:13.604361Z","updated_at":"2021-08-17T07:23:13.000000Z","created_at":"2021-08-17T07:23:13.000000Z","id":29,"tax_rate":25}}]