Home > Software design >  Problem with the booking calendar in Laravel 8
Problem with the booking calendar in Laravel 8

Time:09-12

I have a problem with the booking calendar on my app in Laravel 8. Please i really need help :(

After pressing the 'book' button, an error pops up:

Illuminate\Contracts\Container\BindingResolutionException Target class [FrontendController] does not exist. http://localhost/testowa7/public/makeReservation/26/5

Room blade:

<form action="{{ route('makeReservation',['room_id'=>$room->id,'city_id'=>$room->object->city->id]) }}" method="POST">
                    <div >
                        <label for="dayin">Przyjazd</label>
                        <input required name="dayin" type="text"  id="dayin" placeholder="">
                    </div>
                    <div >
                        <label for="dayout">Wyjazd</label>
                        <input required name="dayout" type="text"  id="dayout" placeholder="">
                    </div>
                    <button type="submit" >Rezerwuj</button>
                    <p >{{ Session::get('reservationMsg') }}</p>
                    {{ csrf_field() }}
                </form>

Route:

 Route::post('/makeReservation/{room_id}/{city_id}','FrontendController@makeReservation')->name('makeReservation');

FrontendController:

public function makeReservation($room_id, $city_id, Request $request)
    {

      $avaiable = $this->fG->checkAvaiableReservations($room_id,$request);

      if(!$avaiable)
      {
          if(!$request->ajax())  // niepotrzebne bez apki
          {
            $request->session()->flash('reservationMsg',_('No vanancies'));
            return redirect()->route('room',['id'=>$room_id,'#reservation']);
          }

          return response()->json(['reservation'=>false]);  //niepotrzebne bez apki

      }
      else
      {
        $reservation = $this->fG->makeReservation($room_id,$city_id,$request);

        if(!$request->ajax())
        return redirect()->route('adminHome');
        else
        return response()->json(['reservation'=>$reservation]);

      }
      
    }

FrontendRepository:

 public function makeReservation($room_id, $city_id, $request)
  {
    return Reservation::create([

      'user_id' => $request->user()->id,
      'city_id' => $city_id,
      'room_id' => $room_id,
      'status' => 0,
      'dayin' => $request->input('dayin'),
      'dayout' => $request->input('dayout'),

    ]);
  }

FrontendGateway:

public function checkAvaiableReservations($room_id,$request)
  {
    $reservations = $this->fR->getReservationsByRoomId($room_id);

    $avaiable = true;

    foreach($reservations as $reservation)
    {
        if( $request->input('dayin') >= $reservation->day_in
          && $request->input('dayin') <= $reservation->day_out
        )
        {
          $avaiable =false;break;
        }
        elseif( $request->input('dayout') >= $reservation->day_in
          && $request->input('dayout') <= $reservation->day_out
        )
        {
          $avaiable =false;break;
        }
        if( $request->input('dayin') >= $reservation->day_in
          && $request->input('dayout') <= $reservation->day_out
        )
        {
          $avaiable =false;break;
        }
    }


    return $avaiable;

  }


  public function makeReservation($room_id, $city_id, $request)
  {
    $this->validate($request, [
      'dayin' => "required|string",
      'dayout' => "required|string",
    ]);

    return $this->fR->makeReservation($room_id, $city_id, $request);
  }

CodePudding user response:

Make sure your FrontendController class namespace is imported into your web.php file.

CodePudding user response:

Make sure your FrontendController is imported correctly

  • Related