<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: drnwork</title>
    <description>The latest articles on DEV Community by drnwork (@drnwork).</description>
    <link>https://dev.to/drnwork</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F720373%2F857da430-a853-4cd6-ae96-580bc236c00e.png</url>
      <title>DEV Community: drnwork</title>
      <link>https://dev.to/drnwork</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/drnwork"/>
    <language>en</language>
    <item>
      <title>How to create associative table in laravel?</title>
      <dc:creator>drnwork</dc:creator>
      <pubDate>Wed, 06 Oct 2021 11:16:37 +0000</pubDate>
      <link>https://dev.to/drnwork/how-to-create-associative-table-in-laravel-obm</link>
      <guid>https://dev.to/drnwork/how-to-create-associative-table-in-laravel-obm</guid>
      <description>&lt;p&gt;I want to create associative table , I have Many to Many relationship between L_Examen_Categorie and L_Examen_SousCategorie. My associative table named L_Examen_Categorie_Souscategorie where i am going to insert id_categorie and id_soucsategorie .&lt;/p&gt;

&lt;p&gt;By the way I am getting the data from other tables P_Examen_Categorie and P_Examen_SousCategorie&lt;/p&gt;

&lt;p&gt;Here is it my code: &lt;/p&gt;

&lt;p&gt;$categorie = DB::table('P_Examen_Categorie as p')&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            -&amp;gt;where('p.id_examen', '=', $id_examen)&lt;br&gt;
            -&amp;gt;get();
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    foreach ($categorie as $cat_item) {

        $l_cat_item = array(
            'code' =&amp;amp;gt; $cat_item-&amp;amp;gt;code,
            'libelle' =&amp;amp;gt; $cat_item-&amp;amp;gt;libelle,
            'id_examen' =&amp;amp;gt; $cat_item-&amp;amp;gt;id_examen,
            'Note' =&amp;amp;gt; $cat_item-&amp;amp;gt;Note,
            'coefficient' =&amp;amp;gt; $cat_item-&amp;amp;gt;coefficient,
            'id_lexamen' =&amp;amp;gt; $id
        );
        L_Examen_Categorie::insert($l_cat_item);
        $idcat=L_Examen_Categorie::get('id');
            $cat_item = DB::table('P_Examen_SousCategorie as p')
                -&amp;amp;gt;select('id', 'code', 'id_categorie', 'libelle', 'Note', 'coefficient')
                -&amp;amp;gt;where('p.id_categorie', '=', $cat_item-&amp;amp;gt;id)
                -&amp;amp;gt;get();


            foreach ($cat_item as $item) {
                $l_souscat_item = array(
                    'code' =&amp;amp;gt; $item-&amp;amp;gt;code,
                    'libelle' =&amp;amp;gt; $item-&amp;amp;gt;libelle,
                    'Note' =&amp;amp;gt; $item-&amp;amp;gt;Note,
                    'coefficient' =&amp;amp;gt; $item-&amp;amp;gt;coefficient,
                    'id_categorie' =&amp;amp;gt; $item-&amp;amp;gt;id_categorie,
                );
                L_Examen_SousCategorie::insert((array)$l_souscat_item);
                $model = array(
                    'id_categorie' =&amp;amp;gt;$cat_item-&amp;amp;gt;id,
                    'id_souscategorie' =&amp;amp;gt;$item-&amp;amp;gt;id,
                );
                L_Examen_Categorie_Souscategorie::insert($model);
            }
    } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Laravel #php&lt;br&gt;
&lt;/h1&gt;

</description>
      <category>laravel</category>
      <category>php</category>
    </item>
  </channel>
</rss>
