I'm making a reservation system, this is the table that I'm currently using.I can't get the foreign key value of client payment. I already put the relationship in the models.
Booking
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class booking extends Model
{
protected $fillable = ['clientID', 'checkInDate', 'checkOutDate', 'roomsCount', 'roomTypeID', 'adultsCount', 'childrenCount', 'amenityID', 'paymentID'];
//public $incrementing = false;
public function client()
{
return $this->belongsTo('App\Client','clientID');
}
public function payment()
{
return $this->hasOne('App\Payment');
}
public function amenities()
{
return $this->hasOne('App\Amenities');
}
Client
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class client extends Model
{
protected $fillable = ['fullNmae', 'firstName', 'lastName', 'phoneNumber', 'emailAddress'];
public function booking()
{
return $this->hasMany('App\Booking');
}
}
Payment
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class payment extends Model
{
protected $fillable = ['clientID', 'paymentMethod', 'invoiceNum', 'accountName', 'amountPaid', 'datePaid', 'payment_image', 'comments'];
public function booking()
{
return $this->belongsTo('App\Booking');
}
}
I'm currently using this to access the foreign key
$bookingDetail = booking::with('client', 'payment')->get();
return view('detail')
->with('bookingDetail', $bookingDetail);
view
Error I'm Getting
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'clients.id' in 'where clause' (SQL: select * from
clients
whereclients
.id
in (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17))
Is this the right way to do it? or am I missing something. I'm new to laravel so I don't know if this is the right way to do it
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire