I have function for image upload which during product creation. This is the function in createSubmit in the controller
public function productsCreateSubmit()
{
$product = new Product;
$product->title = Input::get('title');
$product->price = Input::get('price');
if (Input::hasFile('image')) {
$file = Input::file('image');
$filename = str_random(20);
$file->move('uploads/', $filename . '.' . $file->getClientOriginalExtension());
$imagePath = 'uploads/' . $filename . '.' . $file->getClientOriginalExtension();
$image = Image::make($imagePath);
if ($image->width() > 200) {
$image->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
});
}
if ($image->height() > 200) {
$image->resize(null, 200, function ($constraint) {
$constraint->aspectRatio();
});
}
$image->save();
} else {
$imagePath = 'default.png';
}
$product->image = $imagePath;
$product->save();
return Redirect::to('/admin/products');
}
When I click on submit I receive the error that column in database doesn't have default value.
SQLSTATE[HY000]: General error: 1364 Field 'file_id' doesn't have a default value (SQL: insert into
products(title,price,image) values (test, 1, uploads/awy3CvVHLajER1E1gfpu.jpg))
The problem is that I don't have such a column in the table. This is the model of product
class Product extends Eloquent
{
protected $table = 'products';
protected $primaryKey = 'product_id';
public $timestamps = false;
}
How the laravel decide to insert/look for this field?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire