2017-09-11 58 views
0

請我需要幫助,即時通訊在laravel開源項目的工作,這是一個預訂房間的系統,每一件事情的工作很好,但存在的財產以後在我不能全日曆腳本看到我創建的事件,但是當我VEW源頁我看到正確的事件,但它無法在日曆活動不完整的日曆顯示laravel

表明這是全日曆腳本代碼預訂的索引頁:

@inject('request', 'Illuminate\Http\Request') 
@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 App\Http\Controllers\Admin; 

use App\Booking; 
use Illuminate\Http\Request; 
use Illuminate\Support\Facades\Gate; 
use App\Http\Controllers\Controller; 
use App\Http\Requests\Admin\StoreBookingsRequest; 
use App\Http\Requests\Admin\UpdateBookingsRequest; 

class BookingsController extends Controller 
{ 
    /** 
    * Display a listing of Booking. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    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 \Illuminate\Http\Response 
    */ 
    public function create() 
    { 
     if (! Gate::allows('booking_create')) { 
      return abort(401); 
     } 

     $rooms = \App\Room::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 \App\Http\Requests\StoreBookingsRequest $request 
    * @return \Illuminate\Http\Response 
    */ 
    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 \Illuminate\Http\Response 
    */ 
    public function edit($id) 
    { 
     if (! Gate::allows('booking_edit')) { 
      return abort(401); 
     } 

     $rooms = \App\Room::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 \App\Http\Requests\UpdateBookingsRequest $request 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    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 \Illuminate\Http\Response 
    */ 
    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 \Illuminate\Http\Response 
    */ 
    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 \Illuminate\Http\Response 
    */ 
    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 \Illuminate\Http\Response 
    */ 
    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 Illuminate\Database\Eloquent\Model; 
use Carbon\Carbon; 
use Illuminate\Database\Eloquent\SoftDeletes; 

/** 
* 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', 'Admin\BookingsController'); 
    Route::post('bookings_mass_destroy', ['uses' => 'Admin\[email protected]', 'as' => 'bookings.mass_destroy']); 
    Route::post('bookings_restore/{id}', ['uses' => 'Admin\[email protected]', 'as' => 'bookings.restore']); 
    Route::delete('bookings_perma_del/{id}', ['uses' => 'Admin\[email protected]_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'  
       }, 
           ] 
     }) 
    }); 

回答

0

對於初學者來說,as per documentation,事件的結束時間是根據end屬性定義的。

而且,我不知道,如果你的的'{{$booking->date.' '.$booking->start_time}}'行不會給你格式化喜歡'Y-m-d Y-m-d H:i:s'東西(因爲你已經返回從你start_timefinish_time屬性全日期時間字符串)。

最後,你的$zeroDate = str_replace(['Y', 'm', 'd'], ['0000', '00', '00'], config('app.date_format') . ' H:i:s');行似乎並不有很大的用途。我看到你想要在這裏做什麼,但是這行只會給你類似'0000-00-00 H:i:s'的東西,我懷疑這是你想要的時候檢查一個空的日期值(而不是您應該在該數據庫字段上使用空值,並在您的getMutator)中檢查。

+0

但當我點擊查看頁面源時,我看到了這個結果,這是什麼意思?我更新了我的問題,並添加了結果,我看到點擊查看頁面源時,請檢查 –

+0

嗯,這只是意味着你沒有在你的模型中的日期屬性。 Laravel將返回null,它將被序列化爲一個空字符串。 (這就是爲什麼你看到日期字符串前面的空格。) – sebwas

+0

只需將該行更改爲'「{{$ booking-> start_time}}」'和'「{{$ booking-> finish_time}}」'並且你很高興與此合作。然而,爲了使你的整個事情工作,你仍然需要改變你的JS對象屬性爲「結束」,並修復空檢查。另外,一定要配置/轉換你的日期格式,這樣momentjs可以理解它,並且留意JS控制檯以查看可能的錯誤。 – sebwas