Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Laravel 5.4 Kalendarz, Błąd podczas pobierania czasu eventu
K3n0
post
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 3.05.2016

Ostrzeżenie: (0%)
-----


Witam,
Mam problem z pobieraniem danych start i end. Chodzi mi o to, że gdy pobieram dane z bazy tytuł eventu pobiera się, ale niestety czas podany przez użytkownika nie. Cały event ustawia się na "allDay" mimo, że ustawiony jest na false.
Podczas tworzeniu eventu wszystko jest ok tytul nazwa start i koniec dodaja sie do bazy danych. Już nie wiem gdzie robię błąd. Czy poprostu start i end nie zostają przekazane do kalendarza.

Plik HomeModel.php
  1. namespace App;
  2.  
  3. use Illuminate\Database\Eloquent\Model;
  4.  
  5. class HomeModel extends Model
  6. {
  7. protected $table = 'events'; // you may change this to your name table
  8. public $timestamps = true; // set true if you are using created_at and updated_at
  9. protected $primaryKey = 'id'; // the default is id
  10. }

Controller
  1. namespace App\Http\Controllers;
  2.  
  3. use Illuminate\Http\Request;
  4. use App\HomeModel;
  5. use MaddHatter\LaravelFullcalendar\Event;
  6. use Illuminate\Support\Facades\DB;
  7. use DateTime;
  8.  
  9. class HomeController extends Controller
  10. {
  11. /**
  12.   * Create a new controller instance.
  13.   *
  14.   * @return void
  15.   */
  16. public function __construct()
  17. {
  18. $this->middleware('auth');
  19. }
  20. /**
  21.   * Show the application dashboard.
  22.   *
  23.   * @return \Illuminate\Http\Response
  24.   */
  25. public function index(){
  26. $event = HomeModel::all();
  27.  
  28. foreach ($event as $eve) {
  29. $events[] = \Calendar::event(
  30. $eve->title, //event title
  31. $eve->name,
  32. $eve->start, //start time (you can also use Carbon instead of DateTime)
  33. $eve->end, //end time (you can also use Carbon instead of DateTime)
  34. $eve->id //optionally, you can specify an event ID
  35. );
  36. //die($event);
  37. }
  38. $calendar = \Calendar::addEvents($events)
  39. ->setOptions([
  40. 'FirstDay' => 1,
  41. 'contentheight' => 650,
  42. 'editable' => false,
  43. 'allDay' => false,
  44. 'aspectRatio' => 2,
  45. 'slotLabelFormat' => 'HH:mm:ss',
  46. ])->setCallbacks([]);
  47. return view('home', compact('calendar'));
  48. }
  49. /**
  50.   * Show the form for creating a new resource.
  51.   *
  52.   * @return \Illuminate\Http\Response
  53.   */
  54. public function create()
  55. {
  56. return view('create');
  57. }
  58. /**
  59.   * Store a newly created resource in storage.
  60.   *
  61.   * @param \Illuminate\Http\Request $request
  62.   * @return \Illuminate\Http\Response
  63.   */
  64. public function store(Request $request)
  65. {
  66. $time = explode(" - ", $request->input('daterange'));
  67.  
  68. $event = new HomeModel;
  69. $event->name = $request->input('name');
  70. $event->title = $request->input('title');
  71. $event->start = $time[0];
  72. $event->end = $time[1];
  73. $event->save();
  74.  
  75. $request->session()->flash('success', 'The event was successfully saved!');
  76. return redirect('home/create');
  77. }
  78. }

Widok home.blade.php
  1. @extends('layouts.app')
  2.  
  3. @section('content')
  4.  
  5. @endsection
  6. @section('calendar')
  7. <div class="panel panel-default" >
  8. <div class="panel-body">
  9. <a class="btn btn-default" href="{{ url('/home/create') }}">Create</a>
  10. <a class="btn btn-default" href="{{ url('/home/edit') }}">Edit</a>
  11. <a class="btn btn-default" href="{{ url('/home/delete') }}">Delete</a>
  12. </div>
  13. </div>
  14. <div class="panel-body">
  15. {!! $calendar->calendar() !!}
  16. {!! $calendar->script() !!}
  17. </div>
  18. </div>
  19. @endsection
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 10:00