Как вставить пустое значение для ввода текста и установить его в null для базы данных, так как я делаю это, у меня возникает ошибка, потому что строки базы данных не имеют значения.Как я могу сделать это без ошибки?
SQLSTATE [23000]: Нарушение ограничения целостности: 1048 Заголовок столбца не может быть пустым (SQL: вставить в awards
(title
, description
, awards_image
, updated_at
, created_at
) значения (,, a: 0: {}, 2018-11-28 10:29:35, 2018-11-28 10:29:35))
РЕДАКТИРОВАТЬ
<?php
foreach ($awards as $key => $values) {
$awardsContent = new Award;
$awardsContent->title = $request->title[$key];
$awardsContent->description = $request->description[$key];
$awardsContent->awards_image = $values;
$awardsContent->save();
}
Контроллер
public function store(Request $request)
{
$this->validate($request, [
'title' => 'nullable',
'description' => 'nullable',
'awards_image.*' => 'image|nullable|max:1999'
]);
$awards = [];
if ($request->has('awards_image')) {
foreach ($request->file('awards_image') as $key => $file) {
$filenameWithExt = $file->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $file->getClientOriginalExtension();
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
$path = $file->storeAs('public/awards_images', $fileNameToStore);
array_push($awards, $fileNameToStore);
}
$fileNameToStore = serialize($awards);
} else {
$fileNameToStore = 'noimage.jpg';
}
$awardsContent = new Award;
$awardsContent->title = $request->input('title');
$awardsContent->description = $request->input('description');
$awardsContent->awards_image = $fileNameToStore;
$awardsContent->save();
return redirect('/admin/airlineplus/awards')->with('success', 'Content Created');
}