hayek's avatar

Best practice for many models in one form

I have a model Product and model Page.

Product has fields:

  • id
  • price and other...

Page has fields:

  • id
  • url and other

Product is inherits a Page.

I would like bulid a form to edit Product, with all fields on Product and all fields on Page.

I can't use:

{!! Form::model($product...

because it assumed one model. How I can doing one form for two or more models?

0 likes
2 replies
RachidLaasri's avatar

Rename the variable to something more generic? "item" for example?

ProductsController :

public function show($id)
{
    $item = Product::findOrFail($id);
}

PagesController :

public function show($id)
{
    $item = Page::findOrFail($id);
}

But, if you ask me, i would definitely separate them and have a file for each one, just in case i needed more flexibility in the future?

hayek's avatar

No, Product and Page has URL attribute. Because I "Products extends Page".

Product has OneToOne relation to Page.

Please or to participate in this conversation.