One controller and inserting data into more than one table (Mass Assignment)

85 views Asked by At

I have a website that users can send their product (like car, mobile, computers) and sell it online on my website, maybe something like Ebay and Amazon.

I have ads table that store all public information about one thing using Mass Assignment, and other categories like Mobile, Car and Computers have their own table and will store professional and additional information of that category on it (for example Cars have some additional information like color, fuel type, guaranty, accidents,insurance).

Now as you know (for mobile) I have two tables (ads and ads_mobile), and for all forms I have a controller that is adsController and ads model, form will create dynamically and each form has its own inputs (For Example:Mobile and car has different inputs and fields), and I just send all dynamic forms to adsController@check and then I check what kind of form it is (is that Mobile? is that Car? or ...?) and then I will send this data to model:

//adsController(This is just Example);
 class Ad extends Eloquent {

  protected $fillable_ads = array('field_one', 'field_two', 'field_three');

}

 Class Mobile_ad extends Eloquent {
   //And I want to use fillable_mobile_ads too
   protected $fillable_mobile_ads = array('field_one', 'field_two', 'field_three');
 }

How to send data from one controller to two models?

Is this possible?

How should be model and controller (suggestion)?

any suggestion for the structure of my website?

0

There are 0 answers