0

Ok, I guess the right way to start is: HALP!
So to start I will give you an introduction to my Problem:

I am working on a booking system for Vacation-Rental-Homes.
The user is creating new Bookings via a Form where he can select a guest, an house (both via dropdowns), a beginning date for the reservation and an ending date.
Problem: I want that in the datepickers, the dates where the selected house is booked will be disabled. For solving this I have made an Helper-Function that is returning me all Bookings for a House.

<?php

namespace App\Http\Controllers;

use App\House;
use Illuminate\Http\Request;
use DB;
use App\Quotation;
use DateInterval;
use DatePeriod;
use DateIntercal;

class HelperFunctions extends Controller
{
    public static function GetBlockedTimes(House $house)
    {
        $Bookings = DB::table('bookings')->where([
                                                     ['House_id', $house->id],
                                                 ])->get();
        $BlockedTimes = [];
        foreach($Bookings as $booking) {
            for($i = strtotime($booking->From); $i <= strtotime($booking->Until); $i += 86400) {
                array_push($BlockedTimes, date('Y-m-d',$i));
            }
        }
        return $BlockedTimes;
    }
}

Also I have stumbled upon This Datepicker Framemork, but to be honest, I (as a C# developer making a Laravel Thingy for the first time) have no Idea how I can implement it into my Laravel Collective Forms. Maybe you can help me there too. For making a page where the User can create Bookings I have made the following View, which is fed by the Controller with all houses and Guests.

@extends('layouts.app')
@section('content')
    <h1>Create Season</h1>
    {!! Form::open(['action' => 'SeasonController@store', 'method' => 'POST']) !!}
    <div class="form-group">
        {{ Form::label('SeasonName','Season Name') }}
        {{ Form::text('SeasonName', '', ['class' => 'form-control', 'placeholder' => 'Season Name'] )  }}
    </div>
    <div class="form-group">
        {{ Form::label('From','From') }}
        @php

        //HALP!!!!!

            use App\Http\Controllers\HelperFunctions;
            use App\House;
            $house = House::find('1'); //This '1' should get replaced by the id selected in House_id
            $home = HelperFunctions::GetBlockedTimes($house);
            $getit = '[';
            if($home == null){
            echo "ERROR!!!";}
            else{
            foreach($home as $date){
            $getit.='"'.$date.'"'.', ';
            }
            }
            $getit .=']';
        @endphp
        {!! Form::date('From', \Carbon\Carbon::now()) !!} {{--In here dates should get disabled according to the select down below--}}
    </div>
    <div class="form-group">
        {{ Form::label('Until','Until') }}
        {!! Form::date('Until', \Carbon\Carbon::now()) !!} {{--In here dates should get disabled according to the select down below--}}
    </div>
    <div class="form-group">
        {{ Form::label('Price','Price') }}
        {!! Form::number('Price',null,['class' => 'form-control','step'=>'any']) !!}
    </div>
    <div class="form-group">
        {{ Form::label('House_id','House') }}
        {!! Form::select('House_id', $houses, null , ['placeholder' => 'Pick a house...',]) !!}{{--This select should change the disabled dates of the datepickers above.--}}
    </div>
    {{ Form::submit('Submit',['class' => 'btn btn-success']) }}
    {!! Form::close() !!}
@endsection

If you need any other informations I am keen to help you! Thank you for your service!

TheDoc
  • 1
  • what you want - is changing form in real time(after selecting house you want change-show selector with date). For me its Ajax request, which after selecting house, will return 2 elements with disabled dates. Btw, as far i know html input can't disable some dates. It only can accept min-max date. – Colohanin Nik Aug 19 '18 at 20:53
  • see this thred https://stackoverflow.com/questions/15400775/jquery-ui-datepicker-disable-array-of-dates – Colohanin Nik Aug 19 '18 at 21:00
  • Ok, thank you for your help, AJAX was a step towards the solution. But now, I can not get any data between my AJAX Script and my PHP script. AJAX: https://pastebin.com/dREKvyPg PHP: https://pastebin.com/THzHUB9C Any ideas? – TheDoc Aug 20 '18 at 19:54

0 Answers0