Search code examples
laravellaravel-ui

Creating admins table separate in Laravel 8


I am creating a Laravel project for the users. Laravel has its own laravel/ui package, but I am creating its admin panel too, and I am a bit confused about what I should do for admins. Also, I am confused about the security for the admin panel. So there are 2 solutions in my mind:

  1. Add a new column in the user's table named status, and if its value is admin, he can access the admin panel; otherwise, redirect to the homepage.
  2. Create a separate admins table and improve laravel/ui auth. For that, I found documentation here.

What should I do? Even i have added table prefix for tables in .env & config/database.php. I am afraid that the hackers/users should not access the admin panel. And also, tell me if the table prefix is good for security, or should I remove the table prefix?


Solution

  • You need the permission-roles system.

    https://spatie.be/docs/laravel-permission/v4/introduction

    This is good decision for you. With well-configured routes no one wont have access in admin panel without access in data base.

    For example, in panel page only admin have access:

    Route::name('adminspace.')->group(['middleware' => ['role:admin']], function () {
            
        Route::view('/panel', 'pages.panel');
    });