Welcome Guest, Not a member yet? Register   Sign In
Accessing Shield User entity properties
#1

(This post was last modified: 09-01-2024, 10:23 PM by evansharp.)

When I use the helper and reference 

PHP Code:
auth()->user()->attributes 


it's always NULL.

If I dd() or var_dump() auth()->user() though, it shows $attributes is an array with juicy values like 'username'. How do I get that juice?

Also, where did the forum search go?
Reply
#2

(09-01-2024, 10:23 PM)evansharp Wrote: When I use the helper and reference 

PHP Code:
auth()->user()->attributes 


it's always NULL.

If I dd() or var_dump() auth()->user() though, it shows $attributes is an array with juicy values like 'username'. How do I get that juice?

Also, where did the forum search go?
It's on the very top of the forums in the ToolBar.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

You need to make sure they are logged in first. If a user is not logged in, `auth()->user()` will return `null`, and you won't be able to retrieve their details.
Reply
#4

(This post was last modified: 09-02-2024, 07:18 PM by evansharp.)

(09-02-2024, 05:23 PM)datamweb Wrote: You need to make sure they are logged in first. If a user is not logged in, `auth()->user()` will return `null`, and you won't be able to retrieve their details.

`auth()->user()` does not return null though. If I `dd()` the object returned, I can see all the properties and methods. I get null when I try to access those properties though with `auth()->user()->attributes`.

(09-01-2024, 10:41 PM)InsiteFX Wrote:
(09-01-2024, 10:23 PM)evansharp Wrote: When I use the helper and reference 

PHP Code:
auth()->user()->attributes 


it's always NULL.

If I dd() or var_dump() auth()->user() though, it shows $attributes is an array with juicy values like 'username'. How do I get that juice?

Also, where did the forum search go?
It's on the very top of the forums in the ToolBar.
ToolBar wasn't displaying. It is  now though. 
Code:
¯\_(ツ)_/¯
Reply
#5

User extend Entity?
$atteibutes this is a protected property, it cannot be read outside the class. Try toArray()
https://codeigniter4.github.io/userguide...properties
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#6

(09-02-2024, 08:45 PM)ozornick Wrote: User extend Entity?
$atteibutes this is a protected property, it cannot be read outside the class. Try toArray()
https://codeigniter4.github.io/userguide...properties

Excellent, thanks!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB