好的,我想正确的开始方法是:HALP!
首先,我将向您介绍我的问题:
我正在为Vacation-Rental-Homes预订系统。
用户正在通过表格创建新的预订,他可以在其中选择客人,房屋(均通过下拉菜单),预订的开始日期和结束日期。
问题:
我希望在日期选择器中禁用所选房屋的预定日期。为了解决这个问题,我做了一个助手功能,可以将我的所有房屋归还给我。
<?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;
}
}
我也偶然发现了This Datepicker Framemork,但老实说,我(作为C#开发人员首次制作Laravel Thingy)不知道如何将其实现到Laravel Collective Forms中。也许您也可以在那里帮助我。 为了制作一个用户可以创建预订的页面,我创建了以下视图,该视图由Controller馈送给所有房屋和来宾。
@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
如果您需要任何其他信息,我们将竭诚为您服务! 谢谢您的服务!