Я получаю некоторые проблемы при вставке моих данных в сводную таблицу. когда я использую return dd($request->education);
Я успешно получил массив.
Но когда я использую приложение
foreach ($request-> образование как образование) {$preq-> education() → attach (['education_id' => $ education]); }
или же
$preq-> education() → attach (['education_id' => $request-> образование]);
Получить некоторую ошибку Call to a member function attach() on null
Вот моя модель Preq
class Preq extends Model {
protected $table = 'preqs';
public function education()
{
$this->belongsToMany(Education::class)->withTimestamps();
}
}
Чтобы связать, вам нужно вернуть объект обратно из education()
class Preq extends Model {
protected $table = 'preqs';
public function education()
{
return $this->belongsToMany(Education::class)->withTimestamps();
}
}
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'SD' for column 'education_id' at row 1 (SQL: insert into
иcreated_at
education_id
preq_id
updated_at
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'SD' for column 'education_id' at row 1 (SQL: insert into
education_preq` (created_at
,education_id
,preq_id
,updated_at
) значения (2017- 12-13 07:30:53, SD, 12, 2017-12-13 07:30:53))return $this->belongsToMany(Education::class, 'preqs')->withTimestamps();