How to insert an empty value to input text and set it to null to database, as I do this Im having an error because the rows of the database does not have a value. how can I do this without an error.
here is my error
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null (SQL: insert into
awards
(title
,description
,awards_image
,updated_at
,created_at
) values (, , a:0:{}, 2018-11-28 10:29:35, 2018-11-28 10:29:35))
my Controller
public function store(Request $request)
{
$this->validate($request, [
'title' => 'nullable',
'description' => 'nullable',
'awards_image.*' => 'image|nullable|max:1999'
]);
$awards = [];
if ($request->has('awards_image'))
{
//Handle File Upload
foreach ($request->file('awards_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$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');
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2TQBEKf
via IFTTT
Aucun commentaire:
Enregistrer un commentaire