title: Laravel Resource
body: <p>I have multiple resources and mostly resource content few fields that are same for all other resource and it's very difficult to modify all the resource in case I need to update/add key/value in the resource.</p>
  
  <p>Is there any way that I can create one main resource that will contain all common fields and then call the main resource in my another resource and add few additional fields.</p>
  
  <p>Here is my controller where I am calling <code>CitizenFeedResource</code> file.</p>
  
  <pre><code>if ($events-&gt;total()) {
              return CitizenFeedResource::collection($events);
          }
  </code></pre>
  
  <p>This is my <code>CitizenFeedResource</code> file.
      
  
  <pre><code>use Illuminate\Http\Resources\Json\JsonResource;
  
  class CitizenFeedResource extends JsonResource
  {
  
      /**
       * Transform the resource into an array.
       *
       * @param  \Illuminate\Http\Request $request
       * @return array
       */
      public function toArray($request)
      {
          return [
              'id' =&gt; $this-&gt;id,
              'title' =&gt; $this-&gt;title,
              'description' =&gt; $this-&gt;description,
              'start_timestamp' =&gt; optional($this-&gt;start_timestamp)-&gt;toDateTimeString(),
              'end_timestamp' =&gt; optional($this-&gt;end_timestamp)-&gt;toDateTimeString(),
              'location' =&gt; [
                  'name' =&gt; $this-&gt;location,
                  'landmark' =&gt; $this-&gt;landmark,
                  'coordinates' =&gt; $this-&gt;coordinates,
                  'city' =&gt; $this-&gt;city,
              ],
              'open_event' =&gt; $this-&gt;open_event,
              'full_day_event' =&gt; $this-&gt;full_day_event,
              'banner' =&gt; $this-&gt;banner,
              'url' =&gt; $this-&gt;path(),
              'web_url' =&gt; $this-&gt;webUrl(),
              'categories' =&gt; $this-&gt;categories,
              'timestamp' =&gt; $this-&gt;created_at-&gt;toDateTimeString(),
              'timestamp_ago' =&gt; $this-&gt;created_at-&gt;diffForHumans(),
              'statistics' =&gt; $this-&gt;statistics,
              'additional_details' =&gt; $this-&gt;additionalDetails(),
              'municipal_details' =&gt; $this-&gt;municipal_details,
              'user' =&gt; optional($this-&gt;user)-&gt;getProfile($this-&gt;channel, '1.1'),
              'complaint_id' =&gt; $this-&gt;complaint_id,
              'volunteers' =&gt; (isset($this-&gt;volunteers) &amp;&amp; $this-&gt;volunteers) ? $this-&gt;user-&gt;getVolunteerProfile($this-&gt;volunteers, '1.1') : array(),
              'share_count' =&gt; (isset($this-&gt;statistics) &amp;&amp; isset($this-&gt;statistics['share_count'])) ? array_sum($this-&gt;statistics['share_count']) : 0,
              'volunteer_status' =&gt; $this-&gt;getVolunteerStatus($request),
              'editable' =&gt; $this-&gt;editable(),
              'type' =&gt; 'Event',
          ];
      }
  }
  </code></pre>