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

angelina-ss's avatar

Gate is not working on production environment

Hello, i have an issue regarding these 2 gates for my app:

Gate::define('admin', function(User $user) {
            return $user->role_id == 1;
});

Gate::define('editor', function(User $user) {
            return $user->role_id == 2 || $user->role_id == 3;
});

these gates worked fine on development env, but it's not working on the production env (Hostinger). I got 403 Forbidden for my routes.

users migration:

Schema::create('users', function (Blueprint $table) {
                $table->engine = 'InnoDB';
                $table->id('user_id')->autoIncrement();
                $table->string('username', 20)->unique();
                $table->string('email')->nullable();
                $table->string('password');
                $table->rememberToken();
                $table->unsignedBigInteger('role_id');
                $table->unsignedBigInteger('staf_id');
                // $table->boolean('ApakahAktif')->default(1);
                $table->timestamps();
                $table->softDeletes();

                $table->foreign('role_id')->references('role_id')->on('role_webs');
                $table->foreign('staf_id')->references('staf_id')->on('stafs');
            });

rolewebs migration:

Schema::create('role_webs', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->id('role_id')->autoIncrement();
            $table->string('nama_role', 30);
            // $table->boolean('ApakahAktif')->default(1);
            $table->timestamps();
            $table->softDeletes();
        });

Are there any settings that i have to commit on my production env? Thank you in advance!

0 likes
14 replies
angelina-ss's avatar

@MohamedTammam hello sir, i just checked the user's role_id, it's not empty and it has the same value from the database

angelina-ss's avatar

@MohamedTammam i use them on my routes sir, such as:

Route::resource('/dashboard/rolewebs', AdminRoleController::class)->except('show')->middleware('admin');

Route::resource('/dashboard/kliens', DashboardKlienController::class)->middleware('editor');
MohamedTammam's avatar
Level 51

@angelina-ss A gate isn't a middleware. It should be

Route::resource('/dashboard/rolewebs', AdminRoleController::class)->except('show')->can('admin');

Route::resource('/dashboard/kliens', DashboardKlienController::class)->can('editor');

PS: I'm surprised it's working on your local.

angelina-ss's avatar

@MohamedTammam sir, i tried to change the gate for my routes with this and it's working. Thank you so much for your help

Route::resource('/dashboard/rolewebs', AdminRoleController::class)->except('show')->middleware('can:admin');

Route::resource('/dashboard/kliens', DashboardKlienController::class)->middleware('can:editor');
1 like
Snapey's avatar

these role numbers. are they arbitrary values or keys from another table?

angelina-ss's avatar

@Snapey no arbitrary sir, every user has a foreign key of role_id from rolewebs table

Please or to participate in this conversation.