请我需要帮助,我在Laravel从事开源项目,这是一个预订室系统,一切都运行良好,但是在完整的日历脚本中有一些东西我看不到我创建的事件,但是当我查看源页面时,我正确看到了该事件,但它没有显示在日历中
这是预订索引页面,其中包含完整日历的脚本代码:
@inject('request', 'IlluminateHttpRequest')
@extends('layouts.app')
@section('content')
<h3 class="page-title">@lang('quickadmin.bookings.title')</h3>
@can('booking_create')
<p>
<a href="{{ route('admin.bookings.create') }}" class="btn btn-success">@lang('quickadmin.qa_add_new')</a>
</p>
@endcan
<link href='//fonts.googleapis.com/css?family=Lato:100,400,700' rel='stylesheet' />
<link href='https://fullcalendar.io/css/base.css?3.5.1-1.7.1-1' rel='stylesheet' />
<link rel='stylesheet' href='https://fullcalendar.io/js/fullcalendar-3.5.1/fullcalendar.min.css' />
<div id='calendar'></div>
@stop
@section('javascript')
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://fullcalendar.io/js/fullcalendar-3.5.1/fullcalendar.min.js'></script>
<script src='https://fullcalendar.io/js/home.js?3.5.1-1.7.1-1'></script>
<script>
$(document).ready(function(){
$('#calendar').fullcalendar({
defaultView: 'agendaWeek',
editable: true,
events:[
@foreach($bookings as $booking)
{
title:'{{$booking->room->name.' '.$booking->room->notes}}',
start:'{{$booking->date.' '.$booking->start_time}}',
finish:'{{$booking->date.' '.$booking->finish_time}}',
url :'{{route('admin.bookings.edit',$booking->id)}}'
},
@endforeach
]
})
});
</script>
@endsection
这是预订控制器:
<?php
namespace AppHttpControllersAdmin;
use AppBooking;
use IlluminateHttpRequest;
use IlluminateSupportFacadesGate;
use AppHttpControllersController;
use AppHttpRequestsAdminStoreBookingsRequest;
use AppHttpRequestsAdminUpdateBookingsRequest;
class BookingsController extends Controller
{
/**
* Display a listing of Booking.
*
* @return IlluminateHttpResponse
*/
public function index()
{
if (! Gate::allows('booking_access')) {
return abort(401);
}
if (request('show_deleted') == 1) {
if (! Gate::allows('booking_delete')) {
return abort(401);
}
$bookings = Booking::onlyTrashed()->get();
} else {
$bookings = Booking::all();
}
return view('admin.bookings.index', compact('bookings'));
}
/**
* Show the form for creating new Booking.
*
* @return IlluminateHttpResponse
*/
public function create()
{
if (! Gate::allows('booking_create')) {
return abort(401);
}
$rooms = AppRoom::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
return view('admin.bookings.create', compact('rooms'));
}
/**
* Store a newly created Booking in storage.
*
* @param AppHttpRequestsStoreBookingsRequest $request
* @return IlluminateHttpResponse
*/
public function store(StoreBookingsRequest $request)
{
if (! Gate::allows('booking_create')) {
return abort(401);
}
$booking = Booking::create($request->all());
return redirect()->route('admin.bookings.index');
}
/**
* Show the form for editing Booking.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function edit($id)
{
if (! Gate::allows('booking_edit')) {
return abort(401);
}
$rooms = AppRoom::get()->pluck('name', 'id')->prepend(trans('quickadmin.qa_please_select'), '');
$booking = Booking::findOrFail($id);
return view('admin.bookings.edit', compact('booking', 'rooms'));
}
/**
* Update Booking in storage.
*
* @param AppHttpRequestsUpdateBookingsRequest $request
* @param int $id
* @return IlluminateHttpResponse
*/
public function update(UpdateBookingsRequest $request, $id)
{
if (! Gate::allows('booking_edit')) {
return abort(401);
}
$booking = Booking::findOrFail($id);
$booking->update($request->all());
return redirect()->route('admin.bookings.index');
}
/**
* Display Booking.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function show($id)
{
if (! Gate::allows('booking_view')) {
return abort(401);
}
$booking = Booking::findOrFail($id);
return view('admin.bookings.show', compact('booking'));
}
/**
* Remove Booking from storage.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function destroy($id)
{
if (! Gate::allows('booking_delete')) {
return abort(401);
}
$booking = Booking::findOrFail($id);
$booking->delete();
return redirect()->route('admin.bookings.index');
}
/**
* Delete all selected Booking at once.
*
* @param Request $request
*/
public function massDestroy(Request $request)
{
if (! Gate::allows('booking_delete')) {
return abort(401);
}
if ($request->input('ids')) {
$entries = Booking::whereIn('id', $request->input('ids'))->get();
foreach ($entries as $entry) {
$entry->delete();
}
}
}
/**
* Restore Booking from storage.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function restore($id)
{
if (! Gate::allows('booking_delete')) {
return abort(401);
}
$booking = Booking::onlyTrashed()->findOrFail($id);
$booking->restore();
return redirect()->route('admin.bookings.index');
}
/**
* Permanently delete Booking from storage.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function perma_del($id)
{
if (! Gate::allows('booking_delete')) {
return abort(401);
}
$booking = Booking::onlyTrashed()->findOrFail($id);
$booking->forceDelete();
return redirect()->route('admin.bookings.index');
}
}
这是预订模式:
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
use CarbonCarbon;
use IlluminateDatabaseEloquentSoftDeletes;
/**
* Class Booking
*
* @package App
* @property string $room
* @property string $booking_name
* @property string $start_time
* @property string $finish_time
* @property string $phone
* @property string $email
* @property string $notes
*/
class Booking extends Model
{
use SoftDeletes;
protected $fillable = ['booking_name', 'start_time', 'finish_time', 'phone', 'email', 'notes', 'room_id'];
/**
* Set to null if empty
* @param $input
*/
public function setRoomIdAttribute($input)
{
$this->attributes['room_id'] = $input ? $input : null;
}
/**
* Set attribute to date format
* @param $input
*/
public function setStartTimeAttribute($input)
{
if ($input != null && $input != '') {
$this->attributes['start_time'] = Carbon::createFromFormat(config('app.date_format') . ' H:i:s', $input)->format('Y-m-d H:i:s');
} else {
$this->attributes['start_time'] = null;
}
}
/**
* Get attribute from date format
* @param $input
*
* @return string
*/
public function getStartTimeAttribute($input)
{
$zeroDate = str_replace(['Y', 'm', 'd'], ['0000', '00', '00'], config('app.date_format') . ' H:i:s');
if ($input != $zeroDate && $input != null) {
return Carbon::createFromFormat('Y-m-d H:i:s', $input)->format(config('app.date_format') . ' H:i:s');
} else {
return '';
}
}
/**
* Set attribute to date format
* @param $input
*/
public function setFinishTimeAttribute($input)
{
if ($input != null && $input != '') {
$this->attributes['finish_time'] = Carbon::createFromFormat(config('app.date_format') . ' H:i:s', $input)->format('Y-m-d H:i:s');
} else {
$this->attributes['finish_time'] = null;
}
}
/**
* Get attribute from date format
* @param $input
*
* @return string
*/
public function getFinishTimeAttribute($input)
{
$zeroDate = str_replace(['Y', 'm', 'd'], ['0000', '00', '00'], config('app.date_format') . ' H:i:s');
if ($input != $zeroDate && $input != null) {
return Carbon::createFromFormat('Y-m-d H:i:s', $input)->format(config('app.date_format') . ' H:i:s');
} else {
return '';
}
}
public function room()
{
return $this->belongsTo(Room::class, 'room_id')->withTrashed();
}
}
这是预订路线:
Route::resource('bookings', 'AdminBookingsController');
Route::post('bookings_mass_destroy', ['uses' => 'AdminBookingsController@massDestroy', 'as' => 'bookings.mass_destroy']);
Route::post('bookings_restore/{id}', ['uses' => 'AdminBookingsController@restore', 'as' => 'bookings.restore']);
Route::delete('bookings_perma_del/{id}', ['uses' => 'AdminBookingsController@perma_del', 'as' => 'bookings.perma_del']);
更新
这是我在查看页面源代码时显示的结果:
<script>
$(document).ready(function(){
$('#calendar').fullcalendar({
defaultView: 'agendaWeek',
events:[
{
title:'room one hy',
start:' 15-09-2017 06:00:00',
finish:' 16-09-2017 09:00:00',
url :'http://127.0.0.1:8000/admin/bookings/5/edit'
},
{
title:'room one hy',
start:' 13-09-2017 07:00:00',
finish:' 13-09-2017 10:00:00',
url :'http://127.0.0.1:8000/admin/bookings/6/edit'
},
{
title:'room one hy',
start:' 27-09-2017 07:11:00',
finish:' 29-09-2017 09:13:00',
url :'http://127.0.0.1:8000/admin/bookings/7/edit'
},
{
title:'room one hy',
start:' 27-09-2017 07:00:00',
finish:' 30-09-2017 08:00:00',
url :'http://127.0.0.1:8000/admin/bookings/8/edit'
},
{
title:'room one hy',
start:' 04-10-2017 04:00:00',
finish:' 04-10-2017 09:00:00',
url :'http://127.0.0.1:8000/admin/bookings/9/edit'
},
]
})
});
对于初学者来说,根据文档,事件的结束时间是按end
属性定义的。
另外,我不确定您的'{{$booking->date.' '.$booking->start_time}}'
行是否会为您提供类似'Y-m-d Y-m-d H:i:s'
格式的内容(因为您已经从start_time
和finish_time
属性返回了完整的日期时间字符串)。
最后,你的$zeroDate = str_replace(['Y', 'm', 'd'], ['0000', '00', '00'], config('app.date_format') . ' H:i:s');
路线似乎没有太大的目的。我知道你想在这里做什么,但这行只会给你类似'0000-00-00 H:i:s'的东西,我怀疑这是你在检查空日期值时想要的(相反,你应该在该数据库字段上使用 nullable 并在你的getMutator中检查它)。