SQLSTATE [42S02]:找不到基表或视图:1146表'seaurchin.availableroom'不存在(42S02)

时间:2018-12-29 11:30:31

标签: laravel laravel-5 eloquent

我正在尝试由客户在指定日期获得可用的房间。到目前为止,我尝试使用join和left join来获得可用空间。

控制器    

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\RedirectResponse;
use App\client;
use App\reservation;
use App\booking;
use App\availableRoom;
use App\roomType;
use App\amenities;
use App\payment;
use App\roomReserved;
use App\Mail\ReservationDetail;
use Carbon\Carbon;
class ReservationController extends Controller
{

    private $_availablerooms;

    /**
     * ReservationController constructor.
     */
    public function __construct()
    {
        $this->_availablerooms = new availableRoom();
    }


    /**
     * @param Request $request
     * @return mixed
     */
    public function checkAvailable(Request $request){
        $checkInDate = date("d-m-Y", strtotime($request->start_date));
        $checkOutDate = date("d-m-Y", strtotime($request->end_date));

        $availableRooms = $this->_availablerooms->from('availableRoom as r')
            ->selectRaw('*,r.roomDoorNum, r.isAvailable, rt.title as roomType,res.roomReservedID')
            ->join('roomtype as rt','rt.roomTypeID','=','r.roomTypeID')
            ->leftjoin('roomReserved as rr','rr.roomID','=','r.roomID')
            ->leftjoin('reservation as res','res.roomReservedID','=', DB::raw('rr.roomReservedID AND (res.reservationDate BETWEEN '."$checkInDate".' AND ' ."$checkOutDate". ' OR res.expiryDate BETWEEN '."$checkInDate".' AND ' ."$checkOutDate".')' ))
            ->get();

        return $availableRooms;
        //return view('rooms');lorem
    }



}

问题是我现在收到此错误。

  

SQLSTATE [42S02]:未找到基表或视图:1146表   “ seaurchin.availableroom”不存在(42S02)

可用的房型

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class availableRoom extends Model
{
    protected $primaryKey = 'roomID';
   protected $fillable = ['roomTypeID', 'roomDoorNum', 'isAvailable'];
    public function roomAmenity()
    {
        return $this->hasMany('App\roomAmenity');
    }
    public function roomType()
    {
        return $this->hasOne('App\roomType');
    }
    public function roomAsset()
    {
        return $this->hasMany('App\roomAsset');
    }
}

roomType模型

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class roomType extends Model
{


    protected $primaryKey = 'roomTypeID';
    protected $fillable = ['title', 'nightRate', 'capacity', 'childrenAllowed', 'maxAdult', 'description'];
    public function availableRoom()
    {
        return $this->hasMany('App\availableRoom');
    }

}

房间预订的模型

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class roomReserved extends Model
{
  protected $primaryKey = 'roomReservedID';
  protected $fillable = ['reservationID', 'roomID'];
  public function reservation()
  {
      return $this->hasOne('App\Reservation');
  }
}

预订模式

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class reservation extends Model
{
  protected $primaryKey = 'reservationID';

 protected $fillable = ['reservationDate', 'expiryDate', 'paymentReceived', 'status', 'actualCheckIn', 'actualCheckOut', 'roomReservedID'];
  public function booking()
  {
      return $this->hasOne('App\Booking');
  }
  public function roomReserved()
  {
      return $this->hasMany('App\roomReserved');
  }
}

0 个答案:

没有答案