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

aj-php's avatar
Level 2

Guidance on Project: Role-Based App

Hi everyone,

I’m developing an internal app for a small company and am a bit stuck on what direction to take and which packages to use. Here’s what I’ve done and where I’m at:

Using Laravel 11

Installed Spatie for permissions/roles

Added Laravel Nova for admin

The app needs public pages for non-logged-in users. Registered users will have role-based access to certain pages (permissions via Nova if needed).

No SEO needed, just internal use.

Questions:

  1. How should I handle menus dynamically? Based on roles?

  2. What’s the best way to create and manage pages in this scenario? I hav

I’m happy to pay for any packages if needed. All guidance is welcome!

Thanks!

PS: I saw: Larafast: awesome! Yet I am not selling anything

Statamic: looks good! Maybe this?

Voyager: also looks good, this one maybe?

0 likes
2 replies
LaryAI's avatar
Level 58

To address your questions about developing a role-based app using Laravel, here are some solutions and recommendations:

1. Handling Menus Dynamically Based on Roles

To handle menus dynamically based on user roles, you can leverage the Spatie permissions package you've already installed. Here's a basic approach:

  • Define Menu Items: Create a configuration file or a database table to define your menu items, including which roles have access to each item.

  • Middleware or Blade Directives: Use middleware or Blade directives to conditionally display menu items based on the user's role.

Here's a simple example using Blade directives:

// In a Blade view file
<ul>
    @can('view dashboard')
        <li><a href="/dashboard">Dashboard</a></li>
    @endcan

    @can('view reports')
        <li><a href="/reports">Reports</a></li>
    @endcan

    @can('view settings')
        <li><a href="/settings">Settings</a></li>
    @endcan
</ul>

In this example, the @can directive checks if the authenticated user has the specified permission before rendering the menu item.

2. Creating and Managing Pages

For creating and managing pages, especially if you want a CMS-like experience, you have a few options:

  • Custom Page Management: You can create a simple page management system using Laravel Nova. Create a Page model with fields like title, slug, content, and role_access. Use Nova resources to manage these pages.

  • Statamic: If you want a more robust CMS solution, Statamic is a great choice. It integrates well with Laravel and provides a user-friendly interface for managing content. However, it might be overkill if you only need basic page management.

  • Voyager: Voyager is another option that provides a simple admin interface for managing content. It's less flexible than Statamic but might be sufficient for your needs.

Here's a basic example of a Page model and migration if you choose to build a custom solution:

// Migration for pages table
Schema::create('pages', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->string('slug')->unique();
    $table->text('content');
    $table->string('role_access')->nullable(); // Comma-separated roles
    $table->timestamps();
});

// Page model
class Page extends Model
{
    protected $fillable = ['title', 'slug', 'content', 'role_access'];

    public function roles()
    {
        return explode(',', $this->role_access);
    }
}

In your controller or middleware, you can then check if the current user's role is allowed to view the page.

Conclusion

  • Use Spatie's permissions to dynamically render menus based on user roles.
  • For page management, consider using Laravel Nova for a custom solution or explore Statamic/Voyager for more CMS-like features.

These approaches should help you build a flexible and maintainable role-based application. If you have further questions or need more detailed guidance, feel free to ask!

1 like
aj-php's avatar
Level 2

I wanted to add: the pages for this app will be about 12, and they won't change (no blog or comments/posts).

Please or to participate in this conversation.