I created an Update for a Products table that is related to another table that is the Product (product_info) for this product. But when I do Update I change the Product information, I delete the article and re-create an article with the same or new content. It's all working fine but I wanted to know if it's a good programming practice or if there is another way.
Basically this is it:
Controller:
$product = Product::find($id);
$product->display_name = Input::get('name_display');
$product->save();
$product->Product_info()->delete();
$product_info = New Product_info;
$product_info->name = Input::get('name');
$product_info->description = Input::get('description');
$product_info->Product()->associate($product);
$product_info->save();
Model: Product.php
public function Product_info()
{
return $this->hasOne('App\Product_info');
}
PS: If I was not explicitly let me know.