Check what's the user's role id.
Jul 1, 2022
14
Level 1
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!
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.
Please or to participate in this conversation.