Sorry if this question is asked elsewhere, but I've searched everywhere but couldn't find the answer. Well, I'm facing this problem on Laravel 5.0, when i try to get a variable from a request, Im getting null value on Production Server but im getting an empty string on the Development Server. The value is not present on the request, ie the field was empty when the form was submitted. eg.
// ProductController
public function store(Request $request) {
// this field is actually empty in the submitted form
$price = $request->price;
// when it gets to the server this is how this value looks like :
// $price in production server : null
// $price in development server : ''
}
When i try to save the object to a database like
Product::save($request->only('name', 'price'));
I get this error(only on production server)
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'price' cannot be null
NOTE that the price column has 'default 0' on mysql table
Why is this happening?
UPDATE:
All this time i thought the request->input() method returned empty string('') if the field was not present. but just know i looked at the laravel source to see this :
public function input($key = null, $default = null)
{
$input = $this->getInputSource()->all() + $this->query->all();
return array_get($input, $key, $default);
}
here it returns null as the default value. then why am i getting empty string on development server?