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.
Related
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');
How to fix
Call to a member function row() on null
THIS IS MY CONTROLLER
function forwardtrack($param='',$param2='') {
if(sizeof($this->db->get_where('st_forward',array('letter_no' =>$param.'/'.$param2))->result_array())>0 && (!($param.'/'.$param2) )){
$data1['message']= 'notallow';
$this->load->view('track1',$data1);
}
else{
$data1['name']=$this->db->get_where('bpas_user_profiles',array('AgencyMainParentID' =>$this->session->userdata('ministryId'),'AgencyParentID'=>$this->session->userdata('parentID'),'AgencyID'=>$this->session->userdata('agencyID')))->result_array();
$data1['userdeatils']=$this->ag->tracks($param.'/'.$param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
THIS IS MY MODEL
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno))->row();
return $query;
}
THIS VIEW PAGE
<br/>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-envelope-o fa-fw"></i>forward to
</div>
<div class="panel-body">
<form class="form-horizontal" enctype="multipart/form-data" action="#" method="post" id="forwardmessage">
<div class="form-group">
<label for="letter"class="col-xs-12 col-lg-1 col-sm-1 col-md-1">letter_no: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<?php
foreach($userdeatils->row() as $row): ?>
<input name="dakLetterNo" id="dakLetterNo" value="<?php echo $row['dakLetterNo'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- <div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">created: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="copy_to" id="copy_to" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required />
</div> -->
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2 control-label">Attachment: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<input type="file" name="Attachment" id="Attachment">
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Subject: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon" id="subjecterr"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="subject" id="Remark" value="<?php echo $row['Remark'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Place: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="place" id="place" value="<?php echo $row['place'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">from: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="from" id="receieve_add" value="<?php echo $row['receieve_add'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Created: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="created" id="created" value="<?php echo $row['created'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Message: </label> -->
<!-- <div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10"> -->
<!-- <span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span> -->
<!-- <input name="message" id="message" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required /> -->
<!-- </div> -->
<!-- </div> -->
<?php endforeach;?>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">Message: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<textarea class="form-control" id="message" name="message"></textarea>
<span id="messageerr" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">
Forward to
</label>
<div class="col-lg-6 col-xs-12 col-sm-6 col-md-6">
<select name="forwardto[]" id="agency" class="form-control">
<option value="">Select</option>
<?php
foreach($name as $row): ?>
<option value="<?php echo $row['cid']?>">
<?php echo $row['FirstName'].$row['MiddleName'].$row['LastName']?>
</option>
<?php endforeach;?>
</select>
<span id="forwarderr" class="text-danger"></span>
</div>
Model:
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno));
if ($query->num_rows() > 0) {
return $query->row();
} else {
return array();
}
}
Controller:
function forwardtrack($param = '', $param2 = '') {
if (sizeof($this->db->get_where('st_forward', array('letter_no' => $param . '/' . $param2))->result_array()) > 0 && (!($param . '/' . $param2) )) {
$data1['message'] = 'notallow';
$this->load->view('track1', $data1);
} else {
$data1['name'] = $this->db->get_where('bpas_user_profiles', array('AgencyMainParentID' => $this->session->userdata('ministryId'), 'AgencyParentID' => $this->session->userdata('parentID'), 'AgencyID' => $this->session->userdata('agencyID')))->result_array();
$data1['userdeatils'] = $this->ag->tracks($param . '/' . $param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
View:
<?php
if(!empty($userdeatils)){
foreach($userdeatils as $row) { ?>
//yout html code
...
...
<?php } ?>//foreach close
<?php } ?>//if close
I'm getting an error as "Name and email address are required if not a client" while running the below mentioned code.
Find below the Controller Code:
class UserController extends Controller
{
public function insertform(){
return view('test');
}
public function create(){
$user=Whmcs::AddClient([
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'email' => Input::get('email'),
'address1' => Input::get('address1'),
'city' => Input::get('city'),
'state' => Input::get('state'),
'postcode' => Input::get('postcode'),
'country' => Input::get('country'),
'phonenumber' => Input::get('phonenumber'),
'password2' => Input::get('password2'),
]);
return $user;
}
}
Find below the route code:
Route::get('insert', 'UserController#insertform');
Route::post('create', 'UserController#create')->name('user.create');
The blade file is given below
<div id="content" class="app-content" role="main">
<div class="app-content-body ">
<div class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3">Sign up</h1>
</div>
<div class="wrapper-md" ng-controller="FormDemoCtrl">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading font-bold">create an account</div>
<div class="panel-body">
<form class="bs-example form-horizontal" action="
{{route('user.create')}}" method="post">
<input type = "hidden" name = "_token" value = "<?php echo
csrf_token(); ?>">
<div class="form-group">
<label class="col-lg-2 control-label">firstname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="firstname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">lastname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="lastname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Email</label>
<div class="col-lg-6">
<input type="email" class="form-control" name="email"
placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">address1</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="address1"
placeholder="Subject">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">city</label>
<div class="col-lg-6">
<select class="form-control" name="city">
<option value="-- Select --">-- Select --</option>
<option value="Coimbatore">Coimbatore</option>
<option value="Chennai">Chennai</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">state</label>
<div class="col-lg-6">
<select class="form-control" name="state">
<option value="-- Select --">-- Select --</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Andhra">Andhra</option>
<option value="Karnataka">Karnataka</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">country</label>
<div class="col-lg-6">
<select class="form-control" name="country">
<option value="-- Select --">-- Select --</option>
<option value="India">India</option>
<option value="China">China</option>
<option value="Australia">Australia</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">postcode</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="postcode"
placeholder="postcode">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">phonenumber</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="phonenumber"
placeholder="phonenumber">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">password</label>
<div class="col-lg-6">
<input type="password" class="form-control" name="password2"
placeholder="password">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-sm btn-
success">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
When I run the above code I'm getting an error as below:
{"result":"error","message":"Name and email address are required if not a client"}
suggest me a solution to solve this and post the data in laravel.
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>
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