Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Birb's avatar
Level 1

Separate Page for User and Admin

Following Situation: I have a Dashboard where you can access, a To-do list, with a simple a-Tag. My Task is that, when a user clicks on the a-Tag, the user should get redirected to their own to-do list, where they can only see their to-dos, what is already done. The next step is, when an admin clicks on the same a-Tag, they should get redirected to a separate page, to see all to-dos. The page for the admin is already created and works fine, but users can access the page too.

How can I redirect the admin to the admin page, when he clicks on the a-Tag? If that's not possible, how to archive it somehow else?:)

For information: I have a table for users, admins, roles and role_has_permissions. The admins are in both, users and admins, tables.

If that helps, my "requires" in the composer.json are: "require": { "php": "^8.0.2", "backpack/crud": "^5.0", "backpack/permissionmanager": "^6.0", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.19", "laravel/sanctum": "^2.14.1", "laravel/tinker": "^2.7", "laravel/ui": "^3.4"

If you need more information, just ask for them, I would be happy to provide them.

Please bear with me, since I need clear instructions, so I get everything right ^^ also, please excuse my English, since I'm not a native speaker

Thanks in advance for your answers :)

0 likes
2 replies
AlexSteele's avatar

On the controller, write a function that takes into account the user id, and show the tasks only related to the authenticated user. on the routes, direct them to that from an endpoint, for instance, /mytasks

Write another function on the controller and display all tasks, with an endpoint like /alltasks

There are a couple of ways to display the link in blade, perhaps write a function on the user model that checks for it, such as

    public function hasRole($role)
    {
        //check for user to have a particular role
        if($this->roles()->where('title', $role)->first()){
            return true;
        }
        return false;
    }

and then test for the admin role and display the /alltasks link , else display the /mytasks link on your blade template

Birb's avatar
Level 1

@AlexSteele Thank you for your reply and your explanation.

But how can I check if the user is an admin when I click on the a-tag. I'm a newbie to Laravel and coding, so I'm sorry if I'm overlooking/not getting something obvious here.

My controllers are set up same as my user.php :)

Please or to participate in this conversation.