Empty object given : laravel 5.1 ajax file upload - ajax

HTML form
{!! Form::open(['route' => 'events.store','id'=>'form-create-event','name' => 'form-create-event','files'=>true]) !!}
<div class="card">
<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 !!}">
{{$value->name}}
</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>
×
</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 !!}">
{{$value->firstname}} {{$value->lastname}}
</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 !!}">
{{$value->firstname}} {{$value->lastname}}
</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="{{$group->id}}" label="{{$group->name}} ">
#foreach($users as $value)
<option value="group[{{$group->id}}][{{$value->id}}]" >
{{$value->firstname}} {{$value->lastname}}
</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="{{$group->id}}" label="{{$group->name}} ">
#foreach($users as $value)
<option value="group[{{$group->id}}][{{$value->id}}]">
{{$value->firstname}} {{$value->lastname}}
</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());
}
The Problem : dd($request->event_document) returns empty object
header request
Server response

Most probably you are trying to upload files bigger than in size allowed by your php.ini. so set the value of upload_max_filesize and post_max_size in your php.ini :
; Maximum allowed size for uploaded files.
upload_max_filesize = 10M or whatever size you need
; Must be greater than or equal to upload_max_filesize
post_max_size = 10M

Related

Livewire & Select2

I am using Livewire and Slect2 in my project
and I am code to select 2 javascript also but select 2 value is not passed to the database here is my code
My Blade File
<div class="col-12 col-lg-12 col-sm-12">
<div wire:ignore>
<div class="form-group">
<label for="exampleInputRounded0">Section Name</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-globe-asia text-primary"></i></span>
</div>
<select class="form-control rounded-0 " wire:model="cr_classes_id" id="cr_classes_id" style="width: 100%;" tabindex="-1" aria-hidden="true">
#foreach ($classes as $class)
<option value="{{$class->id}}">{{$class->classes_name}}</option>
#endforeach
</select>
</div>
#error('cr_classes_sec_id') <span class="text-danger error">{{ $message }}</span>#enderror
</div>
</div>
</div>
Here is My JS
#push('js')
<script type="text/javascript">
$(document).ready(function () {
$('#cr_classes_id').select2();
$('#cr_classes_id').on('change', function (e) {
var data = $('#cr_classes_id').select2("val");
#this.set('cr_classes_id', data);
});
});
</script>
#endpush
Consol Error
Uncaught TypeError: Cannot read property '$wire' of undefined
at Livewire.value (index.js:31)
at HTMLSelectElement.<anonymous> (ClassRooms:844)
at HTMLSelectElement.dispatch (jquery.min.js:2)
at HTMLSelectElement.v.handle (jquery.min.js:2)
at Object.trigger (jquery.min.js:2)
at HTMLSelectElement.<anonymous> (jquery.min.js:2)
at Function.each (jquery.min.js:2)
at k.fn.init.each (jquery.min.js:2)
at k.fn.init.trigger (jquery.min.js:2)
at n.select (select2.min.js:2)
without wire:ignore Working find and data send to the database
Try this
<div class="col-12 col-lg-12 col-sm-12">
<div wire:ignore.self>
<div class="form-group">
<label for="exampleInputRounded0">Section Name</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-globe-asia text-primary"></i></span>
</div>
<select class="form-control rounded-0 " wire:change="$emit('classChanged', $event.target.value)" style="width: 100%;" tabindex="-1" aria-hidden="true">
#foreach ($classes as $class)
<option value="{{$class->id}}" {{ $cr_classes_id ? 'selected' : ''}} >{{$class->classes_name}}</option>
#endforeach
</select>
</div>
#error('cr_classes_sec_id') <span class="text-danger error">{{ $message }}</span>#enderror
</div>
</div>
</div>
and in component
public $cr_classes_id = '';
public $listeners = [
'classChanged'
];
......
public function classChanged($value)
{
$this->cr_classes_id = $value;
}
try to add ":key="cr_classes_id_key" in your blade file
<div class="col-12 col-lg-12 col-sm-12">
<div wire:ignore :key="cr_classes_id_key">
<div class="form-group">
<label for="exampleInputRounded0">Section Name</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-globe-asia text-primary"></i></span>
</div>
<select class="form-control rounded-0 " wire:model="cr_classes_id" id="cr_classes_id" style="width: 100%;" tabindex="-1" aria-hidden="true">
#foreach ($classes as $class)
<option value="{{$class->id}}">{{$class->classes_name}}</option>
#endforeach
</select>
</div>
#error('cr_classes_sec_id') <span class="text-danger error">{{ $message }}</span>#enderror
</div>
</div>

Use row data to be inserted into table and update current table Laravel 5.7

I use record data from a table to reduce the entries that the user will make as it will be stored in another table, but after saving it must update the status of the current record to be 'Used'
the current row is in table called airfiles and will be inserted after adding sale amount into table called tickets
here is the airfiles schema code :
public function up()
{
Schema::create('airfiles', function (Blueprint $table) {
$table->increments('id');
$table->string('airl')->nullable();
$table->string('num')->nullable();
$table->date('date')->nullable();
$table->string('pass')->nullable();
$table->string('route')->nullable();
$table->string('dot')->nullable();
$table->string('dor')->nullable();
$table->string('flynumt')->nullable();
$table->string('flynumr')->nullable();
$table->float('fare')->nullable();
$table->float('tax')->nullable();
$table->float('total')->nullable();
$table->float('comm')->nullable();
$table->float('net')->nullable();
$table->string('rloc')->nullable();
$table->string('son')->nullable();
$table->string('acc')->nullable();
$table->string('pcc')->nullable();
$table->tinyInteger('progid')->default('1');
$table->string('status')->nullable();
$table->integer('segment')->nullable();
$table->string('filename')->nullable();
$table->float('k7')->nullable();
$table->string('used')->nullable();
$table->string('transfer')->nullable();
$table->integer('ticket_id')->unsigned()->nullable();
$table->rememberToken();
$table->timestamps();
});
Schema::table('airfiles', function (Blueprint $table) {
$table->foreign('ticket_id')->references('id')->on('tickets')->onDelete('cascade');
});
}
and here is the TicketController code:
public function store(Request $request, $id)
{
$this->validate($request,[
'date'=>'required',
'tkt_no'=>'required',
'sector'=>'required',
'airline'=>'required',
'supplier'=>'required',
'fare'=>'required',
'tax'=>'required',
'total_tax'=>'required',
'total_cost'=>'required',
'k7'=>'required',
'comm'=>'required',
'profit'=>'required',
'sale_price'=>'required',
'sign'=>'required',
'pax_name'=>'required',
'mob'=>'required',
'amount_arabic'=>'required',
'amount_english'=>'required',
'action_type'=>'required',
'trans_type'=>'required',
'payment_type'=>'required',
]);
$ticket = new Ticket();
$ticket->date = $request->get('date');
$ticket->tkt_no = $request->get('tkt_no');
$ticket->sector = $request->get('sector');
$ticket->airline = $request->get('airline');
$ticket->supplier = $request->get('supplier');
$ticket->fare = $request->get('fare');
$ticket->tax = $request->get('tax');
$ticket->total_tax = $request->get('total_tax');
$ticket->total_cost = $request->get('total_cost');
$ticket->k7 = $request->get('k7');
$ticket->comm = $request->get('comm');
$ticket->profit = $request->get('profit');
$ticket->sale_price = $request->get('sale_price');
$ticket->sign = $request->get('sign');
$ticket->branch =Auth::user()->branch_id;
$ticket->pax_name = $request->get('pax_name');
$ticket->mob = $request->get('mob');
$ticket->amount_arabic = $request->get('amount_arabic');
$ticket->amount_english = $request->get('amount_english');
$ticket->action_type = $request->get('action_type');
$ticket->trans_type = $request->get('trans_type');
$ticket->payment_type = $request->get('payment_type');
$ticket->post_flag = '0';
$ticket->save();
Airfile::find($id)->update(['used' => 'Used']);
session()->flash('success',__('site.added_successfully'));
return redirect()->route('$tickets.index');
}
here is the close blade code :
<div class="card-content collpase show">
<div class="card-body">
<form action="{{ route('tickets.store') }}" method="post">
{{ csrf_field() }}
{{ method_field('post') }}
<div class="row">
<div class="form-group col-md-2">
<label>#lang('site.son')</label>
#if(Auth::user()->shortsign == '--')
<select class="select2-size-lg form-control border-primary"
style="width: 100%;" name="sign">
#foreach ($users as $user)
<option
value="{{ $user->shortsign }}">{{ $user->shortsign }}</option>
#endforeach
</select>
#else
<select class="select2-size-lg form-control border-primary"
style="width: 100%;" name="sign" readonly>
<option
value="{{ Auth::user()->shortsign }}">{{ Auth::user()->shortsign }}</option>
</select>
#endif
</div>
<div class="col-md-3">
<div class="form-group">
<label for="pax_name">#lang('site.pax_name')</label>
<div class="position-relative has-icon-left">
<input type="text" id="pax_name" class="form-control"
name="pax_name"
value="{{ $airfiles->pass }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="client">#lang('site.client')</label>
<div class="position-relative has-icon-left">
<input type="text" id="client" class="form-control"
name="client"
value="{{ $airfiles->pass }}">
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="mob">#lang('site.mob')</label>
<div class="position-relative has-icon-left">
<input type="text" id="mob" class="form-control"
name="mob"
value="{{ old('mob') }}">
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="form-group col-md-2">
<label>#lang('site.supplier')</label>
<select class="form-control select2 status-type" style="width: 100%;"
name="supplier"
id="supplier">
<option selected value="bsp">BSP</option>
<option value="online">Online</option>
</select>
</div>
<div class="form-group col-md-2">
<label>#lang('site.action_type')</label>
<select class="form-control select2 status-type" style="width: 100%;"
name="action_type"
id="action_type">
<option selected value="issue">#lang('site.issue')</option>
<option value="reissue">#lang('site.reissue')</option>
<option value="emd">#lang('site.emd')</option>
<option value="refund">#lang('site.refund')</option>
{{-- <option value="void_charge">#lang('site.void_charge')</option>--}}
</select>
</div>
<div class="form-group col-md-2">
<label>#lang('site.trans_type')</label>
<select class="form-control select2 status-type" style="width: 100%;"
name="trans_type"
id="trans_type">
<option selected value="domestic">#lang('site.domestic')</option>
<option value="international">#lang('site.international')</option>
</select>
</div>
<div class="form-group col-md-2">
<label>#lang('site.payment_type')</label>
<select class="form-control select2 status-type" style="width: 100%;"
name="payment_type"
id="payment_type">
<option selected value="cash">#lang('site.cash')</option>
<option value="credit">#lang('site.credit')</option>
<option value="advance">#lang('site.advance')</option>
<option value="pending">#lang('site.pending')</option>
</select>
</div>
<div class="form-group col-md-2">
<label>#lang('site.airline')</label>
<select class="form-control select2 status-type" style="width: 100%;"
name="airline"
id="airline">
#foreach ($airlines as $airline)
<option value="{{ $airline->code }}">{{ $airline->code }}</option>
#endforeach
</select>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="sale_price">#lang('site.sale_price')</label>
<div class="position-relative has-icon-left">
<input type="text" id="sale_price" class="form-control"
name="sale_price" placeholder="0"
onkeypress="return isNumberKey(event)"
{{-- onblur="findTotal()"--}}
onkeyup="main ();eng_main();findTotal()"
value=" {{ old('sale_price') }}">
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="tkt_no">#lang('site.tkt_no')</label>
<div class="position-relative has-icon-left">
<input type="text" id="tkt_no" class="form-control"
name="tkt_no" onkeypress="return isNumberKey(event)"
value="{{ $airfiles->num }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="rloc">#lang('site.rloc')</label>
<div class="position-relative has-icon-left">
<input type="text" id="rloc" class="form-control"
name="rloc"
value="{{ $airfiles->rloc }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="sector">#lang('site.sector')</label>
<div class="position-relative has-icon-left">
<input type="text" id="sector" class="form-control"
name="sector" placeholder="#lang('site.like') : HAS/JED JED/MAA"
value="{{ $airfiles->route }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="fare">#lang('site.fare')</label>
<div class="position-relative has-icon-left">
<input type="text" id="fare" class="form-control "
onblur="findTotal()"
name="fare" placeholder="0"
{{-- onkeyup="main ()"--}}
value="{{ $airfiles->fare }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="tax">#lang('site.tax')</label>
<div class="position-relative has-icon-left">
<input type="text" id="tax" class="form-control"
name="tax" placeholder="0"
onkeypress="return isNumberKey(event)"
onblur="findTotal()"
{{-- onkeyup="return sum(event)"--}}
value="{{ $airfiles->tax }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="k7">#lang('site.k7')</label>
<div class="position-relative has-icon-left">
<input type="text" id="k7" class="form-control"
name="k7" placeholder="0"
onkeypress="return isNumberKey(event)"
onblur="findTotal()"
{{-- onkeyup="return sum(event)"--}}
value="{{ $airfiles->k7 }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="comm">#lang('site.comm')</label>
<div class="position-relative has-icon-left">
<input type="text" id="comm" class="form-control"
name="comm" placeholder="0"
onkeypress="return isNumberKey(event)"
onblur="findTotal()"
{{-- onkeyup="return sum(event)"--}}
value="{{ $airfiles->comm }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="profit">#lang('site.profit')</label>
<div class="position-relative has-icon-left">
<input type="number" id="profit" class="form-control"
name="profit" placeholder="0"
onkeypress="return isNumberKey(event)"
onblur="findTotal()"
{{-- onkeyup="return sum(event)"--}}
value="{{ number_format(old('profit'), 2) }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="total_tax">#lang('site.total_tax')</label>
<div class="position-relative has-icon-left">
<input type="text" id="total_tax" class="form-control"
name="total_tax" placeholder="0"
onkeypress="return isNumberKey(event)"
onkeyup="return sum(event)"
value="{{ old('total_tax') }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="total_cost">#lang('site.total_cost')</label>
<div class="position-relative has-icon-left">
<input type="text" id="total_cost" class="form-control"
name="total_cost" placeholder="0"
onkeypress="return isNumberKey(event)"
onkeyup="return sum(event)"
value="{{ old('total_cost') }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<label for="date">#lang('site.date')</label>
<div class="input-group">
<input id="date" name="date" class="form-control datepicker" type="date"
value="{{ $airfiles->date }}" readonly>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="amount_arabic">#lang('site.amount_arabic')</label>
<div class="position-relative has-icon-left">
<input type="text" id="amount_arabic" class="form-control"
name="amount_arabic"
onkeypress="return isNumberKey(event)"
onkeyup="return sum(event)"
value=" {{ old('amount_arabic') }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="amount_english">#lang('site.amount_english')</label>
<div class="position-relative has-icon-left">
<input type="text" id="amount_english" class="form-control"
name="amount_english"
onkeypress="return isNumberKey(event)"
onkeyup="return sum(event)"
value=" {{ old('amount_english') }}" readonly>
<div class="form-control-position">
<i class="la la-keyboard-o"></i>
</div>
</div>
</div>
</div>
</div>
<div class="form-actions right">
<button id="slide-toast" type="submit"
class="btn btn-outline-warning btn-min-width box-shadow-2 mr-1 mb-1"><i
class="la la-check-square-o"></i> #lang('site.close')</button>
</div>
</form><!-- end of form -->
</div><!-- end of box -->
</div>
here is the route code :
//airfile routes
Route::resource('airfiles', 'AirfileController')->except(['show']);
//ticket routes
Route::resource('tickets', 'TicketController')->except(['show']);
the error i got is :
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
Too few arguments to function App\Http\Controllers\TicketController::store(), 1 passed and exactly 2 expected
any one can help ?
This is because this methods expects an ID and may be you did not pass id from route to this method. you can pass id to route like this:
{{ route('routeName', ['id' => 1]) }}
And make your route like this:
Route::get('appName/{id}', ControllerName#store)->name('routeName');

When I click on edit button give me error

When I click in edit button it gives me a error, what is problem I can not understand now, please help me
Trying to get property 'id' of non-object (View: C:\xampp\htdocs\ytl\resources\views\profile\edit.blade.php)
This is my userprofilecontroller
public function edit( Request $request, $id){
$user_profile_id = UserProfile::where('id', '=', $id)->firstOrFail();
$exchanges = Exchange::pluck('exchange','id')->all();
$markets = Market::pluck('market','id')->all();
$countries = Country::pluck('country','id')->all();
$brokerage_company = BrokerageCompany::pluck ('brokerage_company','id')->all();
$user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile_id','exchanges','markets','countries','brokerage_company','user_profile'));
}
public function update(Request $request, $id){
$user_profile_id = UserProfile::findOrFail($id);
$input = $request->except( 'brokerage_company','user_profile');
$user_id = $user_profile->update($input);
return redirect('/profile');
}
This is profile\index.blade.php file
<div class="card card-table">
<div class="card-header">Basic Tables
<div class="tools dropdown"><span class="icon mdi mdi-download"></span><a class="dropdown-toggle" href="#" role="button" data-toggle="dropdown"><span class="icon mdi mdi-more-vert"></span></a>
<div class="dropdown-menu" role="menu"><a class="dropdown-item" href="#">Action</a><a class="dropdown-item" href="#">Another action</a><a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div><a class="dropdown-item" href="#">Separated link</a>
</div>
</div>
</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th style="width:10%;">Country</th>
<th style="width:10%;">Exchange</th>
<th class="number">Market</th>
<th class="number">Company</th>
<th class="actions">Charges</th>
</tr>
</thead>
#if($user_profile)
<tbody>
#foreach($user_profile as $user_profiles)
<tr>
<td>{{$user_profiles->country->country}}</td>
<td>{{$user_profiles->exchange->exchange}}</td>
<td>{{$user_profiles->market->market}}</td>
<td>{{$user_profiles->brokerage_company->brokerage_company}}</td>
<td class="cell-detail"><span>Intaday-charge</span>{{$user_profiles->charge_intraday}}
<span class="cell-detail-description">Delivery-charge</span>
{{$user_profiles->charge_delivery}}</td>
{{--<td>{{$user_profiles->charge_per_lot}}</td>--}}
{{--<td>{{$user_profiles->charge__per_order}} </td>--}}
<td> <a class="btn btn-info btn-sm" href="{{route('profile.edit', $user_profiles->id)}}">Edit</a></td>
</tr>
#endforeach
</tbody>
#endif
</table>
</div>
</div>
This is profile\edit.blade.php file
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Charge</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{--<form method="PATCH", id="form", action="{{action('Profile\UserProfileController#update',$user_profile_id->id)}} ", accept-charset="UTF-8">--}}
{{--{{ csrf_field() }}--}}
{{--{{ method_field('PATCH') }}--}}
{!! Form::model($user_profile,['method'=>'PATCH', 'action'=> ['Profile\UserProfileController#update',$user_profile->id]]) !!}
<div class="row">
<div class="col-md-6 mb-3 form-group">
Country:<select name="country_id" id="country" class="form-control " onchange="myfunc()" >
<option value="">Select</option>
#foreach($countries as $key=>$val )
<option value="{{ $val->id }}">{{ $val->country }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Exchange:<select name="exchange_id" id="exchange" class="form-control notselect" onchange="myfunc1()">
<option value="">Select</option>
{{--#foreach($exchanges as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->exchange }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Market<select name="market_id" id="market" class="form-control bindselect" >
<option value="">Select</option>
{{--#foreach($markets as $key=>$val )--}}
{{--<option value="{{ $val->id }}">{{ $val->market }}</option>--}}
{{--#endforeach--}}
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Company:<select name="brokerage_company_id" id="brokerage_company_id" class="form-control " >
<option value="">Select</option>
#foreach($brokerage_company as $key=>$val)
<option value="{{ $val->id }}">{{ $val->brokerage_company }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 mb-3 form-group">
Intraday_charge: <input type="text" name="charge_intraday" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_delivery" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_lot" class="form-control"><br>
</div>
<div class="col-md-6 mb-3 form-group">
Delivery_charge: <input type="text" name="charge_per_order" class="form-control"><br>
</div>
{!! Form::close() !!}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" value="Submit" name="form1" class="btn btn-primary">Save changes</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
It seems like you misunderstood the Pluck method. Pluck is to take several properties out an array by their key. Nothing to do with selecting columns from a Database.
I guess you want to select a single UserProfile. And the right way of doing this is as follows:
public function edit(Request $request, $id){
$user_profile = UserProfile::findOrFail($id); // Select a UserProfile by ID or fail
$exchanges = Exchange::all('exchange', 'id');
$markets = Market::all('market','id');
$countries = Country::all('country','id');
$brokerage_company = BrokerageCompany::all ('brokerage_company','id');
// I dont know what you want with this statement?
// $user_profile = UserProfile::pluck('charge_intraday','charge_delivery','charge_per_lot','charge_per_order')->all();
return view('profile.edit', compact('user_profile','exchanges','markets','countries','brokerage_company'));
}

When Pass pdf file in ajax call then file_get_content() gives error

When i try to pass pdf at controller side through ajax at that time file_get_content() gives error like this
file_get_contents(): Filename cannot be empty
My output is like below:-
Illuminate\Http\UploadedFile Object(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 2017-playing-rules.pdf
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1
[hashName:protected] =>
[pathName:SplFileInfo:private] =>
[fileName:SplFileInfo:private] =>
)
Here "[pathName:SplFileInfo:private]=>" gives null response which should have temp path of my uploaded file.
Here is my ajax call:-
$('#formAddLeague').on('success.form.bv', function(e) {
e.preventDefault();
var formData = new FormData(this);
$.ajax({
url:'{{ url('restoreleague') }}',
data:formData,
type:'post',
dataType:'json',
cache: false,
contentType: false,
processData: false,
success: function(data)
{
$('#loader').hide();
if(data.key == 1)
{
notify('League has been updated Successfully.','blackgloss');
}
}
});
});
In controller i used following:-
$import_rule = $request->file('importRule');
Here is my controller:-
public function restore(Request $request)
{
$league_id = $request->get('hiddenLeagueId');
$import_rule = $request->file('importRule');
$league_rule_url = $request->get('txtLeagueRule');
$objLeague = League::find($league_id);
if (!empty($import_rule)) {
$originalName = $import_rule->getClientOriginalName();
$ruleFileName = pathinfo($originalName, PATHINFO_FILENAME) . '.' . pathinfo($originalName, PATHINFO_EXTENSION);
$s3 = Storage::disk('s3');
$filePath = 'league_rules/' . $ruleFileName;
if ($s3->put($filePath, file_get_contents($import_rule) , 'public'))
{
$ruleURL = $s3->url($filePath);
$objLeague->league_rules = $ruleURL;
$objLeague->rules_filename = $ruleFileName;
}
}
else
if (!empty($league_rule_url))
{
$checkExtension = pathinfo($league_rule_url, PATHINFO_EXTENSION);
if ($checkExtension != 'pdf')
{
$msg = "The selected url extension is not valid.";
return $msg;
}
else
{
$objLeague->league_rules = $league_rule_url;
}
}
$objLeague->league_name = $request->get('txtLeagueName');
$objLeague->league_email = $request->get('txtLeagueEmail');
$objLeague->league_phone = $this->replacePhoneNumber($request->get('leagueContactNo'));
$objLeague->league_info = $request->get('txtLeagueInfo');
$objLeague->level_id = $request->get('txtLevel');
$objLeague->age_required = $request->get('txtMinRequiredAge');
$objLeague->league_website = $request->get('leagueWebsite');
$objLeague->save();
$response['key'] = 1;
return $response;
}
Here is my form:-
<div id="tab2" class="tab-pane">
<form id="formAddLeague" method="post">
{{ csrf_field() }}
<input id="hiddenLeagueId" type="hidden" name="hiddenLeagueId" value="{{$leagueDetail->league_id or ''}}">
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label class="control-label"><b>LEAGUE NAME</b></label>
<input type="text" id="txtLeagueName" name="txtLeagueName" value="{{$leagueDetail->league_name or ''}}" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE ID</b></label><br>
<span class="disabled-color" id="leagueId">{{$leagueDetail->league_id or ''}}</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>TYPE OF LEAGUE</b></label>
<select id="txtLevel" name="txtLevel" class="form-control">
<option value="">-- Select Type of League --</option>
#foreach($levelList as $level)
<option value="{{ $level->level_id }}" #if($leagueDetail->level_id == $level->level_id) {{"selected='selected'"}} #endif>{{ $level->level_name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>MIN AGE REQUIREMENT</b></label>
<select id="txtMinRequiredAge" name="txtMinRequiredAge" class="form-control">
<option value="ALL AGES" #if($leagueDetail->age_required == 'ALL AGES') {{ "selected='selected'" }} #endif>All AGES</option>
<option value="18 AND OVER" #if($leagueDetail->age_required == '18 AND OVER') {{ "selected='selected'" }} #endif>18 AND OVER</option>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group" style="overflow: visible!important;">
<label class="control-label"><b>SPORTS OFFERED</b></label>
<select id="txtLevel" name="txtLevel" class="form-control selectpicker" multiple data-style="form-control">
#foreach($levelList as $level)
<option value="{{ $level->level_id }}" #if($leagueDetail->level_id == $level->level_id) {{"selected='selected'"}} #endif>{{ $level->level_name }}</option>
#endforeach
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE EMAIL</b></label>
<input style="text-transform: lowercase;" type="email" id="txtLeagueEmail" name="txtLeagueEmail" value="{{$leagueDetail->league_email or ''}}" class="form-control" placeholder="Enter Your Email">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE PHONE</b></label>
<input placeholder="(xxx) xxx-xxxx" type="text" name="leagueContactNo" id="leagueContactNo" value="{{$leagueDetail->league_phone or ''}}" class="form-control">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label"><b>LEAGUE WEBSITE</b></label>
<input id="leagueWebsite" type="text" name="leagueWebsite" value="{{$leagueDetail->league_website or ''}}" class="form-control" placeholder=" League website">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label"><b>LEAGUE RULES</b></label>
<div class="row">
<div class="col-md-1">
<div class="radio radio-info">
<input type="radio" name="user_radio" id="file_radio" onclick="leagueRule(1)" checked>
<label> Use File </label>
</div>
</div>
<div class="col-md-11">
<div class="col-sm-12">
<div class="fileinput fileinput-new input-group" data-provides="fileinput">
<div class="form-control" data-trigger="fileinput">
<i class="glyphicon glyphicon-file fileinput-exists"></i>
<span class="fileinput-filename"></span>
</div>
<span class="input-group-addon btn btn-default btn-file">
<span class="fileinput-new"><i class="fa fa-upload"></i></span>
<span class="fileinput-exists">Change</span>
<input type="file" name="importRule" id="importRule">
</span>
Remove
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-1">
<div class="radio radio-info">
<input type="radio" name="user_radio" id="url_radio" onclick="leagueRule(2)">
<label> Use URL </label>
</div>
</div>
<div class="col-md-11">
<input disabled type="text" id="txtLeagueRule" name="txtLeagueRule" value="{{$leagueDetail->league_rules or '' }}" class="form-control" placeholder="Enter Link">
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group col-md-12 col-sm-12 col-xs-12">
<label class="control-label"><b>ABOUT</b></label>
<textarea id="txtLeagueInfo" style="resize: none;" class="form-control" rows="3" data-minwords="3" maxlength="238" name="txtLeagueInfo" placeholder="Type your message">{{$leagueDetail->league_info or ''}}</textarea>
<div id="textarea_feedback" style="text-align:right; color: red"></div>
{{-- <div id="textarea_feedback" class="text-left disabled-color"></div> --}}
</div>
</div>
</div>
<div class="form-group text-left p-t-md">
<button type="submit" class="btn btn-info">UPDATE</button>
</div>
</form>
</div>

insert input fied array in laravel 5.2

I want to insert to DB with array input. but have an error. Please help me
this is my code:
in view
Số công văn
<div class="form-group">
<label for="exampleInputpwd1">Người phê duyệt</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-thumbs-o-up"></i></div>
<select class="form-control" name="txtleader[]">
<?php
$list_ld = DB::table('leaders')->select('id','Name')->get();
?>
#foreach($list_ld as $item_ld)
<option value="{!! $item_ld->id !!}">{!! $item_ld->Name !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Lí do xin vé</label>
<div class="input-group">
<div class="input-group-addon"><i class="icon-question"></i></i></div>
<select class="form-control" name="txtlido[]">
<?php
$list_rs = DB::table('reasons')->select('id','Name')->get();
?>
#foreach($list_rs as $item_rs)
<option value="{!! $item_rs->id !!}">{!! $item_rs->Name !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">Công ty</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-bank"></i></div>
<select class="form-control" name="txtCom[]">
<?php
$list_c = DB::table('companies')->select('id','NameCOM')->get();
?>
#foreach($list_c as $item_c)
<option value="{!! $item_c->id !!}">{!! $item_c->NameCOM !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">Phòng</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-building-o"></i></div>
<select class="form-control" name="txtRoom[]">
<?php
$list_r = DB::table('rooms')->select('id','NameRO')->get();
?>
#foreach($list_r as $item_r)
<option value="{!! $item_r->id !!}">{!! $item_r->NameRO !!}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">Giao cho</label>
<div class="input-group">
<div class="input-group-addon"><i class="ti-share"></i></div>
<input type="text" class="form-control" id="exampleInputuname" placeholder="Chi nhánh/Đại diện nhận nhiệm vụ" name="txtReceiver[]">
</div>
</div>
<div class="form-group">
<div class="checkbox checkbox-success"></div>
</div>
<div class="text-right"></div>
</div>
<div class="col-md-6">
<div class="form-group nguoixin">
<label for="exampleInputuname">Người xin</label>
<div class="input-group">
<div class="input-group-addon"><i class="icon-user"></i></div>
<input type="text" class="form-control" id="exampleInputuname" placeholder="Người xin" name="txtnguoixin[]">
<input type="text" class="form-control" id="exampleInputuname" placeholder="Người xin" name="txtnguoixin[]">
<div class="input-group-addon"><button class="add-more-nx"><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputuname">Mối quan hệ</label>
<div class="input-group">
<div class="input-group-addon"><i class="ti-exchange-vertical"></i></div>
<select class="form-control" name="txtRelation[]">
<?php
$list_rl = DB::table('relationship')->select('id','Name')->get();
?>
#foreach($list_rl as $item_rl)
<option value="{!! $item_rl->id !!}">{!! $item_rl->Name !!}</option>
#endforeach
</select>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Người đi</label>
<div class="input-group">
<div class="input-group-addon"><i class="icon-people"></i></div>
<textarea class="form-control" rows="5" name="txtGuest[]"></textarea>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd1">chặng bay</label>
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-fighter-jet"></i></div>
<select class="form-control" name="txtFlies[]">
<?php
$list_cb = DB::table('return')->select('id','CodeFN')->get();
?>
#foreach($list_cb as $item_cb)
<option value="{!! $item_cb->id !!}">{!! $item_cb->CodeFN !!}</option>
#endforeach
</select>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputpwd2">mức giảm</label>
<div class="input-group">
<div class="input-group-addon"><i class="ti-package"></i></div>
<select class="form-control" name="txtDiscount[]">
<?php
$list_dc = DB::table('discounts')->select('id','CodeDist')->get();
?>
#foreach($list_dc as $item_dc)
<option value="{!! $item_dc->id !!}">{!! $item_dc->CodeDist !!}</option>
#endforeach
</select>
<div class="input-group-addon"><button><i class="fa fa-plus"></i></button></div>
</div>
</div>
<div class="form-group">
<div class="checkbox checkbox-success"> </div>
</div>
<div class="text-right">
<button type="submit" class="btn btn-success waves-effect waves-light m-r-10">Thêm mới</button>
</div>
</form>
my controller
$input = Input::all();
$count = count($input['txtnguoixin']);
$ticketin = array();
for($i=1; $i<$count; $i++){
if($input['txtnguoixin'][$i]){
array_push($ticketin, array(
'NoCV' => $input['txtSCV'][$i],
'nguoixin' => $input['txtnguoixin'][$i],
'Com_id' => $input['txtCom'][$i],
'Room_id' => $input['txtRoom'][$i],
'Reason_id' => $input['txtlido'][$i],
'Nguoidi' => $input['txtGuest'][$i],
'Relation_id' => $input['txtRelation'][$i],
'return_id' => $input['txtFlies'][$i],
'discount_id' => $input['txtDiscount'][$i],
'leader_id' => $input['txtleader'][$i],
'nguoinhap' => 'muoi',
'assignto' => $input['txtReceiver'][$i],
'tinhtrang' => 1
));
}
}
echo "<pre>";
print_r($ticketin);
echo "</pre>";
But it has erro undefined offset 1.

Resources