I have a 1: n relationship between the Language table and the Users
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->unsignedBigInteger('lang_id_1');
$table->unsignedBigInteger('lang_id_2')->nullable();
$table->unsignedBigInteger('lang_id_3')->nullable();
$table->text('img')->nullable();
$table->rememberToken();
$table->string('api_token', 64)->unique()->default(Str::random(50));
$table->timestamps();
$table->foreign('lang_id_1')
->references('id')
->on('languages');
$table->foreign('lang_id_2')
->references('id')
->on('languages');
$table->foreign('lang_id_3')
->references('id')
->on('languages');
});
Schema::create('languages', function (Blueprint $table) {
$table->id();
$table->text('name');
$table->timestamps();
});
In order to put the language in the Nova Resource User I go to fill in the fields as follows:
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Gravatar::make()->maxWidth(50),
Text::make('Name')
->sortable()
->rules('required', 'max:255'),
Text::make('Email')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),
Password::make('Password')
->onlyOnForms()
->creationRules('required', 'string', 'min:8')
->updateRules('nullable', 'string', 'min:8'),
Text::make('Api_token')
->sortable()
->rules('required', 'api_token', 'max:254')
->updateRules('unique:users,email,{{resourceId}}','api_token'),
BelongsTo::make('Language'),
BelongsTo::make('Language'), // always refers to the 'lang_id_1'
BelongsTo::make('Language'), // always refers to the 'lang_id_1'
];
}
unfortunately using " BelongsTo::make('Language')," always refers to the 'lang_id_1' field, I would like it to point to the 'lang_id_2' field etc.