Laravel convert object to string example

August 5, 2017 | Category : Laravel PHP

Hey,

Sometimes, we require to convert object to string value, but it's need to very rare case. But if you require to convert laravel eloquent object then you can do it using "(string)". In this example i will show you how to do this.

So, let's see bellow example. I simply get users data using all() method of User model. After that get i will convert that object collections data into string. So let's see bellow example and understand how it works.

Example:

$users = App\User::all();

$users = (string) $users;

dd($users);

I hope you found your solution...

You may also like to see this:

Convert object to array in laravel 5 example

Laravel convert object to json example