title: Add a custom function to a model to retreive specific data
body: <p>I'm building an app to evaluate children in a nursery school. (my wife is a nursery school teacher). This are the basic models and relations:</p>
  
  <pre><code>class Subevaluation extends Model
  {
      // fields: id, title, date, classroom, course_id
      public function subevaluations(){
         return $this-&gt;hasMany('App\Subevaluation');
      }
  }
  
  class Evaluation extends Model
  {
      // fields: id, child_id, evaluation_id, quotation
      public function evaluation(){
         return $this-&gt;belongsTo('App\Evaluation');
      }
  }
  </code></pre>
  
  <p>There are more models in my app (Child, Classroom,...) but the above 2 are the important ones for this issue.</p>
  
  <p>Now I can retrieve all subevaluations of one selected evaluation; for example:</p>
  
  <pre><code>$eval = App\Evaluation::find(1);
  
  $subevals = $eval-&gt;subevaluations;
  </code></pre>
  
  <p>And in my view I can list all the subevaluations:</p>
  
  <pre><code>@foreach($eval-&gt;subevaluations as $subeval)
  
    &lt;td&gt; {{ $subeval-&gt;student-&gt;name }}&lt;/td&gt;
    &lt;td&gt; {{ $subeval-&gt;date }}&lt;/td&gt;
    &lt;td&gt; {{ $subeval-&gt;quotation }}&lt;/td&gt;
  
  @endforeach
  </code></pre>
  
  <p>Here comes my question: (drumrolls...)</p>
  
  <p>I want to be able to list the last 5 quotations made for this specific evaluation/course. So, in the @foreach loop, I want some kind of function like {{ $subeval->last5quotations }} that returns an array like this:</p>
  
  <pre><code>array{
    {
      'quot' =&gt; 'A',
      'date' =&gt; '2017-03-01',
      'info' =&gt; 'info here'
    },
    {
      'quot' =&gt; 'C',
      'date' =&gt; '2017-02-14',
      'info' =&gt; 'info here'
    },
    {
      'quot' =&gt; 'A',
      'date' =&gt; '2017-01-30',
      'info' =&gt; 'info here'
    },
    {
      'quot' =&gt; 'B',
      'date' =&gt; '2016-12-04',
      'info' =&gt; 'info here'
    },
    {
      'quot' =&gt; 'A',
      'date' =&gt; '2016-11-20',
      'info' =&gt; 'info here'
    }
  }
  </code></pre>
  
  <p>This array (or can be collection) has the last 5 quotations given to each child - course</p>
  
  <p>Then I can loop this array an show this info in the view</p>
  
  <p>How can I achieve this in Laravel? (version 5.4)</p>
  
  <p>Thank you!</p>