title: How in Laravel 7 resources show only some fields of a creator?
body: <p>In my Laravel 7.6 app I use resource collection with creator retrieved
  and I want in some cases show not all creator fields, but only some of them. I have in my control:</p>
  
  <pre><code>$activeVotes = Vote
      ::getByStatus('A')
      -&gt;where('votes.id', 1) 
      -&gt;with('voteCategory')
      -&gt;with('creator')
  return (new VoteCollection($activeVotes));
  </code></pre>
  
  <p>In app/Http/Resources/VoteCollection.php I have :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Resources;
  use Illuminate\Http\Resources\Json\ResourceCollection;
  
  class VoteCollection extends ResourceCollection
  {
      public static $wrap = 'votes';
  
      public function toArray($request)
      {
  
          $this-&gt;collection-&gt;transform(function ($votes) {
              return new VoteResource($votes);
          });
  
          return parent::toArray($request);
      }
  }
  </code></pre>
  
  <p>and in app/Http/Resources/VoteResource.php :</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Resources;
  
  use Illuminate\Http\Resources\Json\JsonResource;
  
  class VoteResource extends JsonResource
  {
  
      public static $wrap = 'votes';
      public function toArray($request)
      {
          return [
              'id' =&gt; $this-&gt;id,
              'name' =&gt; $this-&gt;name,
              'creator' =&gt; $this-&gt;whenLoaded('creator'),
              ...
  </code></pre>
  
  <p>How to defined if I need to show only some fields of creator above ?</p>
  
  <p><strong>EDITED:</strong></p>
  
  <pre><code>My app/User.php has :
  
  &lt;?php
  
  namespace App;
  
  use Laravel\Passport\HasApiTokens;
  use Illuminate\Notifications\Notifiable;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  
  use DB;
  ...
  class User extends Authenticatable implements MustVerifyEmail
  {
      use Billable;
      use HasApiTokens, Notifiable;
      use funcsTrait;
      protected $table = 'users';
      protected $primaryKey = 'id';
      public $timestamps = false;
  
      protected $userAvatarPropsArray = [];
      protected $avatar_filename_max_length = 255;
      protected $full_photo_filename_max_length = 255;
      protected static $password_length = 8;
  
      protected $fillable = [ 'username', 'email', 'status', 'provider_name', 'template_id', 'provider_id', 'first_name', 'last_name', 'phone', 'website', 'password',
      'activated_at', 'avatar', 'full_photo', 'updated_at', 'verified' ];
  
      protected $hidden = [ 'password', 'remember_token'  ];
      ...
  
      public function votes()
      {
          return $this-&gt;hasMany('App\Vote', 'creator_id', 'id');
      }
      ...
  </code></pre>
  
  <p>and app/Vote.php :</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use DB;
  use App\MyAppModel;
  use Illuminate\Support\Facades\File;
  use Illuminate\Support\Facades\Storage;
  use App\Http\Traits\funcsTrait;
  use Cviebrock\EloquentSluggable\Sluggable;
  use Illuminate\Validation\Rule;
  
  class Vote extends MyAppModel
  {
      use funcsTrait;
      use Sluggable;
      use HasTags;
  
      protected $table = 'votes';
      protected $primaryKey = 'id';
      public $timestamps = false;
  
      protected $casts = [
          'meta_keywords' =&gt; 'array'
      ];
  
      protected $fillable = ['name', 'slug', 'description', 'creator_id', 'vote_category_id', 'is_quiz', 'status', 'image'];
      protected static $logAttributes = ['*'];
      ...
      public function creator(){
          return $this-&gt;belongsTo('App\User', 'creator_id','id');
      }
  </code></pre>
  
  <p>In Vote and user models there are referenced to other model.
  Otherwize </p>
  
  <pre><code>   -&gt;with('creator')
  </code></pre>
  
  <p>does not work.
  Are there some options I missed?</p>
  
  <p>Thanks!                        </p>