vendredi 2 mars 2018

Use variable in LARAVEL update form

I need to use an old() variable value in a @if condition. When i open the UPDATE form, i see the correct value. But I don't know why, when i use old() in a condition the value is NULL. This form is using in fullcalendar. Actually i use ajax.

FORM UPDATE:

 <!-- FORM per aggiornare eventi -->
{!!Form::open(['route'=>['events.update',1],  'method'=>'PUT', 'id'=>'updatemodal'])!!}
<div class="form-group">
 {!! Form::label('tipologia_evento_id', 'Tipo evento') !!}
 <select id="tipologia_evento_id" name="tipologia_evento_id" class="form-control" disabled>
     @foreach(DB::table('tipologie_eventi')->get() as $tipologia)
         <option
            @if(old('_tipologia_evento_id') == $tipologia->id)
               selected="selected"
            @endif
                value=""></option>
     @endforeach
 </select>
</div>
@if(!in_array(old('_tipologia_evento_id'),array(1,2)))
 <div class="modal-footer">
     <meta name="csrf-token" content="">
     <a id="delete" data-href="" data-id="" class="btn btn-danger">Elimina</a>
     <button id="aggiornaBtn" type="submit" class="btn btn-success" disabled="disabled">Aggiorna</button>
</div>
@endif
{!! Form::close() !!}

AJAX CODE:

        $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,listDay'
        },
        navLinks: true, // can click day/week names to navigate views
        editable: false,
        selectable: true,
        selectHelper: true,

        select: function(start, end){
            start = moment(start.format());
            end = moment(end.format());
            $('#date_start').val(start.format('DD.MM.YYYY'));
            $('#date_end').val(end.format('DD.MM.YYYY HH:mm'));
            $('#responsive-modal').modal('show');
        },

        events: BASEURL + '/events',

        eventClick: function(event, jsEvent, view){
            var date_start = $.fullCalendar.moment(event.start).format('DD.MM.YYYY');
            var time_start = $.fullCalendar.moment(event.start).format('HH:mm');
            var date_end = $.fullCalendar.moment(event.end).format('DD.MM.YYYY HH:mm');

            $('#modal-event #delete').attr('data-id', event.id);

            $('#updatemodal').attr("action", '/events/'+event.id);

            $('#modal-event #title').val(event.title);
            $('#modal-event #description').val(event.description);
            $('#modal-event #date_start').val(date_start);
            $('#modal-event #time_start').val(time_start);
            $('#modal-event #date_end').val(date_end);
            $('#modal-event #responsabile').val(event.responsabile);
            $('#modal-event #tipologia_evento_id').val(event.tipologia_evento_id);
            $('#modal-event').modal('show');
        }
    });

I tried to use @if(!in_array(old('_tipologia_evento_id'),array(1,2))) but not work good. Some advice?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2HXAgPV
via IFTTT

Aucun commentaire:

Enregistrer un commentaire