title: using sum to custom function in laravel
body: <p>i have custom function in my Model</p>
  <pre><code>public function bkd(){
          $sifat = 0;
          $sks = $this-&gt;sks;
          $bkd = 0;
          if($this-&gt;sifat == 'Team Teaching'){
              $sifat = 0.5;
              $bkd = $sifat * $sks;
              return $bkd;
          }elseif($this-&gt;sifat == 'Asistensi'){
              $sifat = 1;
              $bkd = $sifat * $sks;
              return $bkd;
          }
      }
  </code></pre>
  <p>and from that, it will called in the table on the view with foreach.</p>
  <pre><code>@foreach($profil-&gt;kelas as $kls)
            &lt;tr&gt;
            &lt;th scope=&quot;row&quot;&gt;{{ $loop-&gt;iteration }}&lt;/th&gt;
            &lt;td&gt;{{ $kls-&gt;matakuliah-&gt;nama}}&lt;/th&gt;
            &lt;td&gt;{{ $kls-&gt;grup}}&lt;/td&gt;
            &lt;td&gt;{{ $kls-&gt;sifat}}&lt;/td&gt;
            &lt;td&gt;{{ $kls-&gt;sks}}&lt;/td&gt;
            &lt;td&gt;{{ $kls-&gt;semester}}&lt;/td&gt;
            &lt;td&gt;{{ $kls-&gt;tahun_ajaran}}&lt;/td&gt;
            &lt;td&gt;{{ $kls-&gt;bkd()}}&lt;/td&gt;
            &lt;td&gt;
                &lt;a href=&quot;/dosen/{{$profil-&gt;id}}/{{$kls-&gt;id}}/del_kelas&quot; class=&quot;badge badge-danger&quot; onclick=&quot;return confirm('Yakin Ingin Menghapus?')&quot;&gt;DELETE&lt;/a&gt;
            &lt;/td&gt;
            &lt;/tr&gt;
        @endforeach
  </code></pre>
  <p>I want to sum every record from the function bkd(), how can i do it?</p>
  <p>this is what i try in the view</p>
  <pre><code>&lt;li&gt;Jumlah Beban Pengajaran di Sistem Informasi&lt;span&gt;{{$kelas-&gt;sum('bkd')}}&lt;/span&gt;&lt;/li&gt;
  </code></pre>
  <p>but its give me error</p>
  <blockquote>
  <p>App\Kelas::bkd must return a relationship instance.</p>
  </blockquote>