Skip to content
Advertisement

how can I print user_Id from this array format?

IlluminateSupportCollection Object
    (
        [items:protected] => Array
            (
                [0] => stdClass Object
                    (
                        [user_id] => 3
                    )    
            )    
    )

I am using Laravel 8. I want to fetch single data and use it.

Advertisement

Answer

Please don’t use print_r to dump your records. kindly use dd() or dump(). So you have a clear idea about collections. So as of now, you fetch as

$yourCollection->first()->user_id

if you have multiple models you can use loops.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement