vendredi 28 décembre 2018

Property [client] does not exist on this collection instance

I can't get the value of the foreign key that is inside the booking table.

Booking Table

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class booking extends Model
{
    protected $primaryKey = 'bookingID';
   protected $fillable = ['clientID', 'checkInDate', 'checkOutDate', 'roomsCount', 'roomTypeID', 'adultsCount', 'childrenCount', 'amenityID', 'paymentID'];

    public function client()
    {
        return $this->hasOne(Client::class,'clientID');
    }

}

Client Table

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class client extends Model
{
  protected $primaryKey = 'clientID';
   protected $fillable = ['fullNmae', 'firstName', 'lastName', 'phoneNumber', 'emailAddress'];
  public function booking()
  {
      return $this->hasMany(Booking::class);
  }
}

I tried adding the protected $primaryKey = 'bookingID'; and protected $primaryKey = 'clientID'; as suggested in my previous question but now I still can't get just the FirstName from the client table.

$bookingDetail = booking::with('client')->get();
    return  $bookingDetail->client->firstName;



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire