【发布时间】:2020-06-05 04:54:57
【问题描述】:
这是预订表,它有hotel_id
Schema::create('reservations', function (Blueprint $table) {
$table->id();
$table->integer('user_id')->unsigned()->references('id')->on('users');
$table->integer('hotel_id')->unsigned()->references('id')->on('hotel');
$table->string('status')->default('pending');
$table->integer('rooms');
$table->date('checkin');
$table->date('checkout');
$table->timestamps();
我尝试只获取我的酒店 ID,并将其与预订的 hotel_id 进行比较,但不起作用
public function index()
{
$myhotels = hotel::where('created_by',Auth::user()->id)->first('id');
$reservations = Reservation::where('hotel_id',$myhotels)->get();
return view('moderateur/reservation',compact('reservations'));
}
【问题讨论】:
-
试试这个! $myhotels = hotel::where('created_by',Auth::user()->id)->first(); $reservations = Reservation::where('hotel_id',$myhotels->id)->get();
标签: laravel laravel-5 laravel-7