Level 1
typo in user model
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
const LECTURER= 'Lecturer';
const ADMIN = 'Admin';
const REVIEWER = 'Reviewer';
protected $guarded = ['id'];
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i created 3 roles in migration and the data cannot be inserted
users
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id(); // primary key
// main data
$table->bigInteger('nidn')->unique(); // bersifat unik
$table->string('fullname');
$table->string('email')->unique();
$table->string('password');
// identifier
$table->enum('role', ['Admin', 'Lecturer', 'Reviewer']);
// system
$table->timestamp('email_verified_at')->nullable();
$table->timestamps();
$table->rememberToken();
});
user model
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
const LECTURER= 'LECTURER';
const ADMIN = 'Admin';
const REVIEWER = 'Reviewer';
protected $guarded = ['id'];
}
LecturerRequest
class LecturerRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$validation = [
'nidn' => ['required', 'numeric', 'min:4'],
'fullname' => ['required', 'string', 'max:255'],
'email' => ['required', 'email'],
'password' => [
'nullable', 'confirmed', 'string',
Password::min(8)
->letters()
->mixedCase()
->numbers()
->symbols()
->uncompromised()
// ex : P@ssw0rd
],
'role' => ['required', 'string', User::DOSEN]
];
return $validation;
}
}
LecturerController
public function store(LecturerRequest $request, User $user)
{
$data = $request->validated();
$data = $request->role['Lecturer'];
if ($request->filled('password')) {
$data['password'] = bcrypt($data['password']);
} else {
$data['password'] = $user->password;
}
User::query()->create($data);
return redirect()->route('lpp.lecturer.index')->with('success', 'Selamat, data telah berhasil anda tambahkan!');
}
you array of variables to write to model needs to be array of key => value
Please or to participate in this conversation.