Nav bar cleaning in default cakephp layout based on role

Hellow been using cakephp4 and having trouble when redirecting based on role after login. I would like to change what the user see when role logged in is admin or user only.

You have multiple ways to achieve this:

Get user specific data

You already use the Identity Helper of the Authentication Plugin.

It also has a method

$role = $this->Identity->get('role');

This requires your users model to have a role field of course.

Get the whole user object via the request

Alternatively, you can also just get the user object via

$user = $this->request->getAttribute('identity')?->getOriginalData();
pr($user);

And do your template specific logic relative to its fields.

thank you for giving your time to answer my question. I’m not very good at this and my skills are on a beginner level. because of your example it gives me a starting point on how to create the code. Now the code is working and I’ve done what i wanted to happen in my project. Many thanks kind sir! :slight_smile: