title: In laravel how to pass extra data to mutators and accessors
body: <p>What I'm trying to do is to append the comments of each article to the articles object, but the problem is that I need to request different number of comments each time.</p>
  
  <p>and for some reason I need to use <strong>mutators</strong> for that, because some times I request 50 articles and I don't want to loop through the result and append the comments.</p>
  
  <p>So is it possible to do something like the following and how to pass the extra argument.</p>
  
  <p><strong>This the Model:</strong></p>
  
  <pre><code>    class Article extends Model
      {
  
          protected $appends = ['user', 'comments', 'media'];
  
          public function getCommentsAttribute($data, $maxNumberOfComments = 0)
          {
              // I need to set maxNumberOfComments
              return $this-&gt;comments()-&gt;paginate($maxNumberOfComments);
  
          }
      }
  </code></pre>
  
  <p><strong>Here is the controller:</strong></p>
  
  <pre><code>class PostsController extends Controller
  {
  
  
      public function index()
      {
          //This will automatically append the comments to each article but I
          //have no control over the number of comments
          $posts = Post::user()-&gt;paginate(10);
          return $posts;
      }    
  
  }
  </code></pre>
  
  <p><strong>What I don't want to do is:</strong></p>
  
  <pre><code>class PostsController extends Controller
  {
  
  
      public function index()
      {
  
          $articles = Post::user()-&gt;all();
  
          $number = 5;
          User::find(1)-&gt;articles()-&gt;map(function(Article $article) {
              $article['comments'] = $article-&gt;getCommnets($number);
              return $article;
          });
  
          return Response::json($articles);
      }    
  
  }
  </code></pre>
  
  <p>Is there a better way to do it? because I use this a lot and it does not seams right.</p>