Hi every one i have user has applicant relationships
i need to register user in applicant resource and direct create applicant.
12 Replies
Please explain in more detail.
i have form for create applicant in applicant resource and in same time there are some inputs for create user that has one applicant relationships (note: the user that i will created is from user table and the applicant from applicant table )
SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value
INSERT INTO
interviewers
(name
, updated_at
, created_at
) VALUES (khaled, 2024-01-04 09:49:39, 2024-01-04 09:49:39)
->schema([
// Forms\Components\Select::make('user_id')
// ->relationship('user', 'name')
// ->required(),
Fieldset::make('user_id')
->relationship('user')
->schema([
TextInput::make('name'),
TextInput::make('email'),
TextInput::make('password'),
]),
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);user_id is not in fillable on the interviewers relationship.
protected $fillable = [
'name',
'user_id',
];
// Forms\Components\Select::make('user_id')
// ->relationship('user', 'name')
// ->required(), this was work and user_id is exit
Schema::create('interviewers', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->foreignId('userid')->constrained();
$table->timestamps();
$table->softDeletes();
});
now i need to add applicant and its user in one to one relationship. this the previous question any help? and also i need to take the user id for that applicant and assign role to it note: role add by assignRole method by spatie? any one
@toeknee ?
i meant interviewer not applicant
guys help <-->
Please do not tag people and read #✅┊rules
You are not showing your current error, and we are also not here to serve. We will help and as we can
i respect
thanks
just my problem in simple i have user auth table and applicant table, user has one applicant then i creatd applicant resource an i need to create applicant before that create its user this first one the second i have method in user model to assingRole to that user created with applicant thanks
is there another way to solve this issues
Are your users already created before you create an applicant? Or do you create the user and the applicant at the same time?
it the same time
Ok so what you need to do is simplify your form for creating the applicant
All your form needs is:
Then inside your applicant resource you should have a
CreateApplicant.php
file
Inside that file you need to add a function
Inside this function ^ you can intercept the data and use it to create a user for the applicant
so something like this
I hope this helps, let me know if you have any issues with it or if it solves your problemyes i will try it
goes well 👍