У меня есть проблема в моей форме, говорит, что выбранный идентификатор позиции школы недействителен.
Идентификатор выбранной позиции школы недействителен.
каждый раз, когда я отправляю его, я только refre sh и выскакиваю недействительным, и я не знаю, что является проблема в моем контроллере регистров
** это мой контроллер **
<div class="form-group row">
<label for="schoolposition_id" class="col-md-4 col-form-label text-md-right">{{ __('schoolposition_id') }}</label>
<div class="col-md-6">
<select id="schoolposition_id" type="schoolposition_id" class="form-control @error('schoolposition_id') is-invalid @enderror" name="schoolposition_id" value="{{ old('schoolposition_id') }}" required autocomplete="schoolposition_id ">
@foreach ( $positions as $position)
<option value="{{ $position->id }} "> {{ $position->school_position }}</option>
@endforeach
</select>
@error('schoolposition_id')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
это мой контроллер регистров
protected function validator(array $data)
{
return Validator::make($data, [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'contact' => ['required', 'numeric ', 'min:11'],
'department_id' => ['required', 'string', 'max:255'],
'schoolposition_id' => ['required','in:user,admin'],
'email' => ['required', 'string', 'email', 'max:255','unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
if ($data['schoolposition_id'] == "admin") {
return Admin::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'contact' => $data['contact'],
'department_id' => $data['department_id'],
'schoolposition_id' => $data['schoolposition_id'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
} else {
return User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'contact' => $data['contact'],
'department_id' => $data['department_id'],
'schoolposition_id' => $data['schoolposition_id'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
}
Администратор. php Модель
public function schoolpositions()
{
return $this->belongsTo("App\Schoolposition",'schoolposition_id' , 'id');
}
public function posts()
{
return $this->belongsTo("App\Post",'post_id' , 'id');
}
//public function students(){
//return $this->hasMany('App\Student');
//}
public function departments()
{
return $this->belongsTo("App\Department",'department_id' , 'id');
}
}
Школьное положение. php
protected $guarded = [];
public function admins()
{
return $this->hasMany("App\Admin");
}
public function dashboards()
{
return $this->hasMany("App\Dashboard");
}
public function users()
{
return $this->hasMany("App\User");
}
Таблица администратора
Schema::create('admins', function (Blueprint $table) {
$table->bigIncrements('id');
//$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('schoolposition_id');
$table->unsignedBigInteger('department_id');
$table->string('first_name');
$table->string('last_name');
$table->string('contact');
$table->string('department')->nullable();
$table->string('schoolposition')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
стол для ученического обучения
Schema::create('students', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('schoolposition_id');
$table->unsignedBigInteger('department_id');
$table->string('first_name');
$table->string('last_name');
$table->string('contact');
$table->string('department')->nullable();
$table->string('schoolposition')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->timestamps();
});