Search code examples
phplaravellumen

Laravel insert record in 2 tables from single model


I am using Lumen(Laravel), structure of 2 tables is given below

Language:
id,
lanugae_name,

Language_country
id,
language_id,
country_id,

I have created a model for lanugage table. But i want when i am inserting record in Language table on same time how i can insert its relationship with country in language_country ?


Solution

  • You can use the attach() method

    In your case:

    $language->countries()->attach($countryId);