dimanche 3 juillet 2016

empty object given : laravel 5.1 ajax file upload

    {!! Form::open(['route' => 'events.store','id'=>'form-create-event','name' => 'form-create-event','files'=>true]) !!}
<div class="card">
  <div class="card-header ch-alt m-b-20">
    <h2>Créer un évenement <small>
      </small>
    </h2>
    <!-- <ul class="actions">
      <li>
          <a href="" onclick="location.reload();">
              <i class="md md-cached"></i>
          </a>
      </li>
      <li>
          <a href="#">
              <i class="md md-file-download"></i>
          </a>
      </li>
      <li class="dropdown">
          <a href="#" data-toggle="dropdown">
              <i class="md md-more-vert"></i>
          </a>

          <ul class="dropdown-menu dropdown-menu-right">
              <li>
                  <a href="#">Exportez Excel</a>
              </li>

              <li>
                  <a href="#">Other Settings</a>
              </li>
          </ul>
      </li>
      </ul> -->                   
  </div>
  <div class="card-body card-padding">

    <div class="row">
      <div id="step1" class="col-sm-4">
        <!-- <h3 class="c-gray m-b-15">principales information</h3> -->
        <div class="round round-lg blue">
          <span>1</span>
        </div>
        <div class="form-group fg-float">
          <div class="fg-line">
            <p class="f-200 m-b-5 c-gray">Type d'évènement</p>
            <select id="type_event" name="type_event" class="tag-select" data-placeholder="">
              @foreach($types_events as $value)
              <option value="{!! $value->id !!}" >
                
              </option>
              @endforeach
            </select>
          </div>
        </div>
        <div class="form-group fg-float">
          <div class="fg-line">
            <input type="text" class="input-sm form-control fg-input" data-rule-minlength='2' required="false" id="event_name" name="event_name">
          </div>
          <label class="fg-label">Nom de l'évènement</label>
        </div>
        <!-- <div class="form-group fg-float">
          <div class="fg-line">
            <input type="text" class="input-sm form-control fg-input input-mask" required="true" data-mask="0000-00-00" name="event_begin_date" id="event_begin_date">
          </div>
          <label class="fg-label">Date début (expl 2016-01-30)</label>
          </div> -->
        <div class="input-group form-group">
          <span class="input-group-addon"><i class="md md-event"></i></span>
          <div class="dtp-container dropdown fg-line">
            <input type='text' name="event_begin_date" id="event_begin_date" class="form-control date-picker" data-toggle="dropdown" placeholder="Date début">
          </div>
        </div>
        <!-- <div class="form-group fg-float">
          <div class="fg-line">
            <input type="text" class="input-sm form-control fg-input input-mask"  required="false" data-mask="0000-00-00" id="event_end_date" name="event_end_date">
          </div>
          <label class="fg-label">Date fin (expl 2016-01-31)</label>
          </div> -->
        <div class="input-group form-group">
          <span class="input-group-addon"><i class="md md-event"></i></span>
          <div  class="dtp-container dropdown fg-line">
            <input type='text' id="event_end_date" name="event_end_date" class="form-control date-picker" data-toggle="dropdown" placeholder="Date fin">
          </div>
        </div>
        <div class='form-group fg-float'>
          <div class="fileinput fileinput-new" data-provides="fileinput">
            <span class="btn btn-primary btn-file m-r-10">
            <span class="fileinput-new">Ajouter un document</span>
            <span class="fileinput-exists">Modifier</span>
            <input type="file" id="event_document" name="event_document">
            </span>
            <span class="fileinput-filename"></span>
            <a href="#" class="close fileinput-exists" id="cancelFileUpload" data-dismiss="fileinput">&times;</a>
          </div>
        </div>



        <!-- <div id="event_document_tag_name" class="form-group">

            <input type="text" placeholder="Tag" id="event_document_tag" name="event_document_tag" class="form-control">

        </div> -->

        <div class="form-group fg-float">
          <div class="fg-line">
            <textarea name="event_description"
              id="event_description" required="false" class="form-control">
            </textarea>
          </div>
          <label class="fg-label">Description</label>
        </div>
        <div class="form-group fg-float">
          <div class="fg-line">
            <textarea id="event_info_pr" name="event_info_pr" required="false" class="form-control">
            </textarea>
          </div>
          <label class="fg-label">Informations pratiques</label>
        </div>
        <div class="form-group fg-float">
          <div class="fg-line">
            <textarea name="event_adress" required="false" id="event_adress" class="form-control">
            </textarea>
          </div>
          <label class="fg-label">Adresse</label>
        </div>
      </div>
      <div id="step2" class="col-sm-4">
        <!-- <h3 class="c-gray m-b-15">informations</h3> -->
        <div class="round round-lg blue">
          <span>2</span>
        </div>
        <div class="form-group fg-float">
          <div class="fg-line">
            <p class="f-200 m-b-5 c-gray">Invités
              <a data-toggle="modal" href="#modalDefaultUploadUsers" class="btn btn-success btn-xs waves-effect pull-right">
              <i class="md md-file-upload"></i>
              </a>
              <a style="margin-right: 10px;" data-toggle="modal" href="#modalDefaultAddUser" class="btn btn-success btn-xs waves-effect pull-right">
              <i class="md md-add"></i>
              </a>
            </p>
            <select multiple id="event_publics" name="event_publics[]" class="tag-select" data-placeholder="">
              @foreach($users as $value)
              <option value="{!! $value->id !!}" >
                 
              </option>
              @endforeach
            </select>
          </div>
        </div>
        <div class="form-group fg-float">
          <div class="fg-line">
            <p class="f-200 m-b-5 c-gray">Intervenants 
            </p>
            <select id="event_speakers" name="speakers[]" class="tag-select" multiple data-placeholder="">
              @foreach($users as $value)
              <option value="{!! $value->id !!}" >
                 
              </option>
              @endforeach
            </select>
          </div>
        </div>
        <!-- Groupe et participants -->
        <div class="form-group fg-float">
          <div class="fg-line">
            <p class="f-200 m-b-5 c-gray">Groupes et participants</p>
            <!-- <select id="event_gp_participants" name="gps_participants[]" class="demo" multiple="multiple">
              @foreach($groups as $group)
              @if($group->id !== 1 && $group->id !== 2)
              <optgroup value="" label=" ">
                @foreach($users as $value)
                <option value="group[][]" >
                   
                </option>
                @endforeach
              </optgroup>
              @endif
              @endforeach
              </select> -->
            <select id="event_gp_participants" data-live-search="true" name="gps_participants[]" multiple class="selectpicker">
              @foreach($groups as $group)
              @if($group->id !== 1 && $group->id !== 2)
              <optgroup value="" label=" ">
                @foreach($users as $value)
                <option value="group[][]" >
                   
                </option>
                @endforeach
              </optgroup>
              @endif
              @endforeach
            </select>
          </div>
        </div>
      </div>
      <div id="step3" class="col-sm-4">
        <!-- <h3 class="c-gray m-b-15">informations</h3> -->
        <div class="round round-lg blue">
          <span>3</span>
        </div>
        <div class="table-responsive">
          <table id="data-table-basic" class="table table-striped table-vmiddle">
            <thead>
              <tr>
                <th colspan="3"> 
                  <a class="pull-right" data-toggle="modal" href="#modalWider">
                  Ajouter séance
                  </a>
                </th>
              </tr>
            </thead>
            <tbody>
              <tr></tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <button type="submit" class="btn btn-info"> Enregistrer 
    </button>
    {!! link_to_route('events.index', 'Annuler', [], ['class' => 'btn btn-link']) !!}
  </div>
</div>
{!! Form::close() !!}

Js code

var form = document.forms.namedItem("form-create-event"); console.log(form);

form.addEventListener('submit', function(ev) 
{

  oData = new FormData(form);
  oData.append("seances", seance);

  console.log(oData);

  var oReq = new XMLHttpRequest();
  oReq.open("POST", form.action, true);
  oReq.onload = function(oEvent) {
    if (oReq.status == 200) {
      console.log('success');
    } else {

        console.log('failed');

    }
  };

  oReq.send(oData);
  ev.preventDefault();
}, false);

php code

public function store(Request $request) { return response()->json( $request->all());

}

===========================================

My Problem is :

When I try(dd($request->event_document)) returns empty object

header request



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire