How to return class name in collection instance in laravel?

Member

by addison , in category: PHP Frameworks , 5 months ago

How to return class name in collection instance in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by aniya.jaskolski , 5 months ago

@addison 

In Laravel, you can return the class name of a collection instance by using the get_class() function. Here's an example of how you can do this:

1
2
3
4
5
$collection = collect([1, 2, 3]);

$className = get_class($collection);

echo $className; // Output: IlluminateSupportCollection


This code snippet creates a collection instance using the collect() helper function, and then retrieves the class name of the collection using the get_class() function. The output will be the class name of the collection, which in this case is IlluminateSupportCollection.