SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into
products
(name
,type
,img_url
,updated_at
,created_at
) values (, , img/products/IMG-20170921-WA0003.jpg, 2017-11-24 15:31:41, 2017-11-24 15:31:41))
PHP Code
public function Products(Request $request){
if($request->isMethod('post'))
{
if(Input::hasFile('file')){
$myproduct = new Product();
$myproduct->name=$request->input('name');
$myproduct->type=$request->input('type');
$file = Input::file('file');
$url='img/products/'.$file->getClientOriginalName();
$file->move('img/products',$file>getClientOriginalName());
$myproduct->img_url = $url;
$myproduct->save();
return view("controlpanel.products");
}
}}
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<table>
<tr>
<form action="{{ URL('products') }}" method="post" enctype="multipart/form-data" class="container">
<td>
<label for="name">Product Name</label>
<input type="text" name="name" class="form-control" id="name" required>
</td>
<td>
<label for="type">Product Type</label>
<select class="form-control" name="type" id="type">
<option value="type1">type 1</option>
<option value="type2">type 2</option>
</select>
</td>
<td>
<label for="file">Select Product image :</label>
<input type="file" name="file" id="file">
</td>
<td>
<input type="submit" value="Upload" name="submit" id="sub1">
<input type="hidden" value="{{ csrf_token() }}" name="_token">
</td>
</form>
</tr>
</table>
</body>
</html>
So both Column name & type getting null except img_url, i don't know why? please help
...values (, , img ...
– CD001dd($request->name,$request->type);
under Products method. – Shubham Pokhriyal