Схема миграции/базы данных
Код: Выделить всё
Schema::create('pdlocations', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->decimal('lon', 10, 7);
$table->decimal('lat', 10, 7);
$table->string('map');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')
->references('id')
->on('users');
});
Код: Выделить всё
public function store(PdlocationStoreRequest $request): RedirectResponse
{
$request->merge([
'user_id' => auth()->user()->id,
// 'user_id' => auth()->user(),
]);
$this->validate($request, [
'user_id' => 'required|exists:users,id',
]);
Pdlocation::create($request->validated());
return redirect()->route('admin.pdlocation.index')
->with('success', 'Pdlocation created successfully.');
}
Код: Выделить всё
SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value
insert into
`pdlocations` (`map`, `lon`, `lat`, `updated_at`, `created_at`)
values
(test, 66, 55, 2024 -06 -21 18: 42: 57, 2024 -06 -21 18: 42: 57)
Есть идеи или предложения, чего мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/786 ... ated-table
Мобильная версия