title: Laravel relationship is not loading in Resource?
body: <p>I want to load the relation of order with customer but it is returning <code>null</code> in the postman<br><br>
  <a href="https://i.stack.imgur.com/YFUb6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YFUb6.png" alt="enter image description here"></a></p>
  
  <p><br>
  <strong><em>Customer Model</em></strong></p>
  
  <pre><code>&lt;?php
  
  namespace App;
  use Tymon\JWTAuth\Contracts\JWTSubject;
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Notifications\Notifiable;
  use Illuminate\Contracts\Auth\MustVerifyEmail;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  
  class Customer extends Authenticatable implements JWTSubject
  {
       use Notifiable;
  
  
      protected $fillable = [
          'first_name',
          'last_name',
          'phone_number',
          'postal_code',
          'email',
          'preferred_method_to_contact',
          'password',
          'address',
      ];
  
      protected $hidden = [
          'password', 'remember_token',
      ];
  
      protected $casts = [
          'email_verified_at' =&gt; 'datetime',
      ];
  
      public function getNameAttribute()
      {
          $name = $this-&gt;first_name . " " . $this-&gt;last_name;
          return $name;
      }
  
      public function orders()
      {
        return $this-&gt;hasMany('App\Order');
      }
  
      public function getJWTIdentifier()
      {
          return $this-&gt;getKey();
      }
  
      /**
       * Return a key value array, containing any custom claims to be added to the JWT.
       *
       * @return array
       */
      public function getJWTCustomClaims()
      {
          return [];
      }
  }
  
  </code></pre>
  
  <p><strong><em>Order Model</em></strong></p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Order extends Model
  {
      protected $fillable = [
              'first_name',
              'last_name',
              'email',
              'phone_number',
              'post_code',
              'address',
              'alternative_address',
              'property_type',
              'property_type_other',
              'contract_type',
              'contract_type_other',
              'no_of_bedrooms',
              'no_of_bathrooms',
              'customer_id',
              'best_day',
              'best_time',
              'type_of_cleaning',
          ];
  
  
      public function customers()
      {
          return $this-&gt;belongsTo('App\Customer');
      }
  }
  
  </code></pre>
  
  <p><strong><em>Order Resource</em></strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Resources;
  
  use Illuminate\Http\Resources\Json\JsonResource;
  
  class OrderResource extends JsonResource
  {
      /**
       * Transform the resource into an array.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return array
       */
      public function toArray($request)
      {
          /*return parent::toArray($request);*/
          return [
              'id' =&gt; $this-&gt;id,
              'first_name' =&gt; $this-&gt;first_name,
              'last_name' =&gt; $this-&gt;last_name,
              'email' =&gt; $this-&gt;email,
              'phone_number' =&gt; $this-&gt;phone_number,
              'post_code' =&gt; $this-&gt;post_code,
              'address' =&gt; $this-&gt;address,
              'alternative_address' =&gt; $this-&gt;alternative_address,
              'property_type' =&gt; $this-&gt;property_type,
              'property_type_other' =&gt; $this-&gt;property_type_other,
              'contract_type' =&gt; $this-&gt;contract_type,
              'contract_type_other' =&gt; $this-&gt;contract_type_other,
              'no_of_bedrooms' =&gt; $this-&gt;no_of_bedrooms,
              'phone_number' =&gt; $this-&gt;phone_number,
              'no_of_bathrooms' =&gt; $this-&gt;no_of_bathrooms,
              'customer' =&gt; new CustomerResource($this-&gt;whenLoaded('customers')),
          ];
      }
  }
  
  </code></pre>
  
  <p><strong><em>Customer Resource</em></strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Resources;
  
  use Illuminate\Http\Resources\Json\JsonResource;
  
  class CustomerResource extends JsonResource
  {
      /**
       * Transform the resource into an array.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return array
       */
       public function toArray($request)
      {
          /*return parent::toArray($request);*/
          return [
              'id' =&gt; $this-&gt;id,
              'first_name' =&gt; $this-&gt;first_name,
              'last_name' =&gt; $this-&gt;last_name,
              'email' =&gt; $this-&gt;email,
          ];
      }
  }
  
  </code></pre>
  
  <p>Here is the function in <code>OrderController</code> which is responsible for sending the JSON response</p>
  
  <pre><code>public function store(Request $request)
      {
          $validator = Validator::make($request-&gt;all(), [
              'first_name' =&gt; ['required', 'string', 'max:10'],
              'last_name' =&gt; ['required', 'string', 'max:10'],
              'email' =&gt; ['required', 'string', 'email', 'max:50'],
              'phone_number' =&gt; ['required', 'string', 'max:30'],
              'post_code' =&gt; ['required', 'string', 'max:30'],
              'address' =&gt; ['required', 'string', 'max:300'],
              'alternative_address' =&gt; ['required', 'string', 'max:300'],
              'property_type' =&gt; ['required', 'string', 'max:30'],
              'contract_type' =&gt; ['required', 'string', 'max:30'],
              'no_of_bedrooms' =&gt; ['required', 'string', 'max:30'],
              'type_of_cleaning' =&gt; ['required', 'string', 'max:30'],
              'best_day' =&gt; ['required', 'string', 'max:30'],
              'best_day' =&gt; ['required', 'string', 'max:30'],
          ]);
  
          if ($validator-&gt;fails()) {
              return response()-&gt;json($validator-&gt;errors(), 422);
          }
  
          // $customer = Customer::findOrFail($request-&gt;customer_id);
          $order = Order::create($request-&gt;all());
          // $order = Order::create();
          $order-&gt;load(array('customers'));
  
          return new OrderResource($order);
      }
  </code></pre>
  
  <p>I want the customer details to be loaded along with the order.</p>