Laravel 5.7 Fullcalendar - дневной маршрут с параметрами - PullRequest
0 голосов
/ 15 февраля 2019

Я просто пытаюсь нажать на день в Fullcalendar, который я передаю по ссылке с параметрами (например, route ('booking.create'). Параметрами являются "verhicle_id", "user_id" и date.

У меня есть следующий код (bookingController):

public function booking($id) {
  $reservations = Reservation::where('vehicle_id', $id)->get();
  return view('reservations.index')->with('reservations', $reservations);
}

index.blade.php

@extends('layouts.app')
@section('content')
  <div class="section container">
    <h1>Calendar</h1>
    <div id="calendar" class="tooltipped"></div>
  </div>
@endsection
@section('scripts')

var data = [
    @foreach($reservations as $reservation)
    {
        title : '{{ $reservation->vehicle->name }}',
        start : '{{ $reservation->start_date }}',
        description: '{{ $reservation->vehicle->location->name }} <br>Reservation from: {{ $reservation->user->name }}',
        color: '{{ $reservation->vehicle->color }}',
        url : '{{ route('reservations.edit', $reservation->id) }}'
    },
    @endforeach
];
$(document).ready(function() {

    // page is now ready, initialize the calendar...
    $('#calendar').fullCalendar({
        // put your options and callbacks here
        events: data,
            dayClick: function(date, allDay, jsEvent, view) {
                //here I want to link to CRUD reservations.create with parameter vehicle_id, user_id and date clicked
            },


        eventRender: function (event, element) {
            element.tooltip({
                position: 'top',
                html: event.title + "<br>" + event.description,
                trigger: 'hover'
            });
        }
    });

});
@endsection

Но у меня нет информации или доступа к vehicle_id и user_id в этом коде. Как быМне нужно настроить код, по которому я получаю эту информацию. Я не хочу, поэтому сделайте это модально.

Причина, по которой я хочу это сделать, заключается в том, что пользователю больше не нужно указывать эти данные вcreate-form (являются скрытыми полями).

Извините за мой плохой английский. Я надеюсь, что каждый может помочь мне. С уважением Dimi

1 Ответ

0 голосов
/ 17 февраля 2019

@ ADyson: Спасибо за ваш комментарий.

У меня есть решение по моей проблеме.У меня работает нормально.Но это прототип для меня.

reservationsController:

public function booking($id)
{
    $user_id = 2;
    $reservations = Reservation::where('vehicle_id', $id)->get();
    return view('reservations.index')->with(['reservations' => $reservations, 'vehicleid' => $id, 'userid' => $user_id]);
}

public function store(Request $request)
{
    $reservation = new Reservation;
    $reservation->user_id = $request->input('userid');
    $reservation->vehicle_id = $request->input('vehicleid');
    $reservation->budget_id = $request->input('budget');
    $reservation->start_date = $request->input('date');
    $reservation->end_date = $request->input('date');
    $reservation->save();
    return redirect()->route('reservations.booking', ['id' => $reservation->vehicle_id]);
}

index.blade.php (я работал с модальным в материализации)

@extends('layouts.app')
@section('content')
<div class="section container">
    <h1>Calendar</h1>
    <div id='calendar' class="tooltipped"></div>
    <a class="waves-effect waves-light btn modal-trigger" href="#modal1">Modal</a>
    <!-- Modal Structure -->
    <div id="modal1" class="modal">
      <div class="modal-content">
      <h1>Create Reservation</h1>
        <form class="col s6" action="{{route('reservations.store')}}" method="POST">
        @csrf
        <div class="input-field col s12">
            <select name="budget">
              <option value="1">Budget 1</option>
              <option value="2">Budget 2</option>
              <option value="3">Budget 3</option>
            </select>
            <label>Budget</label>
        </div>
          <input readonly value="" name="vehicleid" id="vehicleid" type="hidden">
          <input readonly value="" name="userid" id="userid" type="hidden">
          <input readonly value="" name="date" id="date" type="hidden">
  </div>
  <div class="modal-footer">
        <button class="btn waves-effect waves-light" type="submit" name="action">Submit
        </button>
    </form>
      </div>
    </div>
</div>
@endsection
    @section('scripts')

    var data = [
        @foreach($reservations as $reservation)
        {
            title : '{{ $reservation->vehicle->name }}',
            start : '{{ $reservation->start_date }}',
            description: '{{ $reservation->vehicle->location->name }} <br>Reserviert: {{ $reservation->user->name }} <br>Seats: {{ $reservation->vehicle->seats }} ',
            color: '{{ $reservation->vehicle->color }}',
            url : '{{ route('reservations.edit', $reservation->id) }}'
        },
        @endforeach
    ];
    $(document).ready(function() {
        @isset($vehicleid)
            var vehicleid = {{$vehicleid}};
        @endisset
        @isset($userid)
            var userid = {{$userid}};
        @endisset
        // page is now ready, initialize the calendar...
        $('#calendar').fullCalendar({
            // put your options and callbacks here
            events: data,
                dayClick: function(date, allDay, jsEvent, view) {
// above I filled the value in the form hidden fields
                    $('#vehicleid').val(vehicleid);
                    $('#userid').val(userid);
                    $('#date').val(date.format());
                    $('#modal1').modal('open');
                    $('.trigger-modal').modal();
                },


            eventRender: function (event, element) {
                element.tooltip({
                    position: 'top',
                    html: event.title + "<br>" + event.description,
                    trigger: 'hover'
                });
            }
        });

    });
@endsection

Если у кого-то естьлучшее решение, пожалуйста, дайте мне знать.С уважением, Дими

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...