title: Laravel 5.4 delete table row and rows from related table
body: <p>When i delete a row from a groups table, i want the function to also delete all relation mapping from table group_user. For example, if i delete group with id 4, all rows in group_user table with group_id 4 are deleted as well. Tables below:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> Schema::create('users', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name');
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('password');
              $table-&gt;string('phone');
              $table-&gt;boolean('approved')-&gt;default(false);
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
   Schema::create('groups', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name');
              $table-&gt;integer('course_id');
              $table-&gt;timestamp('start_date')-&gt;nullable();
              $table-&gt;timestamp('end_date')-&gt;nullable();
              $table-&gt;timestamps();
          });
    Schema::create('group_user', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;integer('user_id');
              $table-&gt;integer('group_id');
              $table-&gt;timestamps();
          });</code></pre>
  </div>
  </div>
  </p>
  
  <p>Currently using this function in group controller, but it only deletes from groups table:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>function deleteGroup($id){
    $group = Group::find($id);
    $group-&gt;delete();
    return redirect()-&gt;back();
   }</code></pre>
  </div>
  </div>
  </p>