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

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');

Related

Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given

I have a form to submit add salarie, the problem here if I delete the function store in controller, it even gives me error instead of giving me error function store does not exist.
SalarieController.php
public function store(request $request){
Salarie::create($request->all());
session()->flash('success','salarie add successfully');
return redirect('salaries');
}
web.php
Route::resource('salaries', 'SalarieController');
create.blade.php
<form action="{{ url('salaries') }}" method="post">
{{ csrf_field() }}
<div class="col-md-12">
<div class="form-group col-md-3 #if($errors->get('matricule')) has-error #endif">
<input type="text" name="matricule" class="form-control" value="{{ old('matricule') }}" placeholder="matricule">
</div>
<div class="form-group col-md-3 #if($errors->get('nom')) has-error #endif">
<input type="text" name="nom" class="form-control" value="{{ old('nom') }}" placeholder="nom">
</div>
<div class="form-group col-md-3 #if($errors->get('prenom')) has-error #endif">
<input type="text" name="prenom" class="form-control" value="{{ old('prenom') }}" placeholder="prenom">
</div>
<div class="form-group col-md-3 #if($errors->get('cin')) has-error #endif">
<input type="text" name="cin" class="form-control" value="{{ old('cin') }}" placeholder="cin">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3 ">
<input type="date" name="daten" class="form-control" value="{{ old('daten') }}" placeholder="date naissance">
</div>
<div class="form-group col-md-3">
<select class="form-control" name="situationf">
<option>celebataire</option>
<option>marie</option>
</select>
</div>
<div class="form-group col-md-3">
<input type="text" name="nbree" class="form-control" value="{{ old('nbree') }}" placeholder="nombre d'enfant">
</div>
<div class="form-group col-md-3">
<input type="text" name="cnss" class="form-control" value="{{ old('cnss') }}" placeholder="matricule CNSS">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3 #if($errors->get('salairenet')) has-error #endif">
<input type="text" name="salairenet" class="form-control" value="{{ old('salairenet') }}" placeholder="salaire net">
</div>
<div class="form-group col-md-3 #if($errors->get('unite')) has-error #endif">
<select class="form-control" name="unite">
<option>Heure</option>
<option>Jour</option>
<option>Mois</option>
</select>
</div>
<div class="form-group col-md-3">
<input type="text" name="hs" class="form-control" value="{{ old('hs') }}" placeholder="tarif HS">
</div>
<div class="form-group col-md-3">
<input type="date" name="datee" class="form-control" value="{{ old('datee') }}" placeholder="date embouche">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3">
<select class="form-control" name="fonction_id">
<option></option>
#foreach($fonctions as $fonction)
<option value="{{ $fonction->id }}">{{ $fonction->fonction}}</option>
#endforeach
</select>
</div>
<div class="form-group col-md-3">
<input type="text" name="primer" class="form-control" value="{{ old('primer') }}" placeholder="prime rendement">
</div>
<div class="form-group col-md-3">
<input type="text" name="primel" class="form-control" value="{{ old('primel') }}" placeholder="prime de longement">
</div>
<div class="form-group col-md-3">
<input type="text" name="primet" class="form-control" value="{{ old('primet') }}" placeholder="prime de transport">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3">
<select class="form-control" name="chantier_id">
<option></option>
#foreach($chantiers as $chantier)
<option value="{{ $chantier->id }}">{{ $chantier->chantier}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-2 col-md-offset-5">
<button type="submit" class="btn btn-theme btn-lg" value="submit">Ajouter</button>
</div>
</div>
</form>
Salarie.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Salarie extends Model
{
public function chantier(){
return $this->belongsTo('App\Chantier');
}
protected $guarded = [];
}
I guess you're missing some options values
here
<select class="form-control" name="situationf">
<option>celebataire</option> // must be <option value="celeb_value">celebataire</option>
<option>marie</option> // must be <option value="marie_value">celebataire</option>
</select>
here also
<select class="form-control" name="unite">
<option>Heure</option> // must be <option value="heure_value">Heure</option>
<option>Jour</option> // must be <option value="jour_value">Jour</option>
<option>Mois</option> // must be <option value="mois_value">Mois</option>
</select>
here too
<select class="form-control" name="fonction_id">
<option></option> // remove empty option or set function_id to nullable
#foreach($fonctions as $fonction)
<option value="{{ $fonction->id }}">{{ $fonction->fonction}}</option>
#endforeach
</select>
and here
<select class="form-control" name="chantier_id">
<option></option> // same as function_id
#foreach($chantiers as $chantier)
<option value="{{ $chantier->id }}">{{ $chantier->chantier}}</option>
#endforeach
</select>

I keep getting an Integrity constraint violation when I'm trying to submit data to db

I have this problem and I have no idea why it's not working. I have tried so many code changes but I still get the same error when I try to submit a form. It's a simple form to insert data to tomany tables in db. All tables accept data with no error but payment_agrement table gives me this error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (kassemschool.payment_agrements, CONSTRAINT payment_agrements_responisbleid_foreign FOREIGN KEY (responsible_id) REFERENCES payment_agrements (id)) (SQL: insert into payment_agrements (frais_inscription, payment_mois, Assurance, Garde, Transport, responsible_id, updated_at, created_at) values (450, 550, 400, 200, 300, 154, 2019-11-16 19:47:39, 2019-11-16 19:47:39))
This is my controller:
if(request()->has('rName')) {
$responsible = Responsible::create([
'ResponsibleName'=> $request->rName,
'ResponsibleCNI'=>$request->cni,
'responsible_number'=>$request->tele
]);
}
//Student::create($data);
if(request()->has('MontantP')) {
$payment=Payment::create([
'PaymentPaid'=>$request->MontantP,
'PaymentRemaining'=>$request->RestP,
'responsible_id'=>$responsible->id,
]);
}
if($request->hasFile('file')){
$student->images = $request->file->store('file');
}
if(request()->has('TransportR')) {
$transport=Transport::create([
'TransportPaid'=> $request->TransportP,
'TransportRemainning'=>$request->TransportR,
'TransportDateStart'=>$request->TdateStart,
'TransportDateEnd'=>$request->TdateEnd,
]);
}
if(request()->has('edateStart')) {
$payment_date = Payment_Date::create([
'PaymentDateStart'=>$request->edateStart,
'PaymentDateEnd'=>$request->edateEnd,
'payment_id'=>$payment->id,
]);
$letter = 'KassN';
$number =$request->env . 'G';
$number2 = $request->group;
$id='_'.rand();
$random = $letter.$number.$number2.$id;
if(request()->has('fName')) {
$student = Student::create([
'StudentFName'=> $request->fName,
'StudentLName'=> $request->lName,
'StudentDateStart'=>$request->edateStart,
'StudentDateEnd'=>$request->edateEnd,
'level_id'=> $request->env,
'group_id'=>$request->group,
'responsible_id'=> $responsible->id,
'payment_date_id'=>$payment_date->id,
'Payment_dure_id'=>$request->paymentD,
'payment_id'=>$payment->id,
'transport_id'=>$transport->id,
'student_code'=>$random
]);
}
if(request()->has('inscription')){
$agrement= Payment_agrement::create([
'frais_inscription'=>$request->inscription,
'payment_mois'=>$request->payment,
'Assurance'=>$request->assaurance,
'Garde'=>$request->garde,
'Transport'=>$request->fraiTransport,
'responsible_id'=>$responsible->id
]);
}
my create view
#extends('layouts.app')
#section('content')
#if (Route::has('login'))
#auth
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
back to <strong>Home</strong>
back to <strong>list</strong>
</div>
#endif
<div class="mr-auto offset-md-1" style="width: 200px;">
<input type="button" class="btn btn-danger btn-sm" name="" value="<- Reteur">
</div>
<div class="card-body">
<div class="container" style="width: 80%;">
<form action="{{url('student')}}" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="firstName">First Name </label>
<input type="text" class="form-control" name="fName" id="elastName">
</div>
<div class="form-group">
<label for="lastName">Last name:</label>
<input type="text" class="form-control" name="lName" id="efirstName">
</div>
<div class="form-group">
<label for="responsable">Responsable Name:</label>
<input type="text" class="form-control" name="rName" id="responsable">
</div>
<div class="form-group">
<label for="cni">Responsable CNI:</label>
<input type="text" class="form-control" name="cni" id="cni">
</div>
<div class="form-group">
<label for="nuveau">Niveau:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="nuveau">Options</label>
</div>
<select class="custom-select" id="nuveau" name="env">
<option selected>Choose...</option>
#foreach($levels as $level)
<option value="{{$level->id}}">{{$level->LevelName}} </option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<fieldset>
<legend>Aggrement:<hr></legend>
<div class="form-group">
<label for="cni">Frais de inscription:</label>
<input type="text" class="form-control" name="inscription" id="cni">
</div>
<div class="form-group">
<label for="cni">paiement mensuel:</label>
<input type="text" class="form-control" name="payment" id="cni">
</div>
<div class="form-group">
<label for="cni">Frais de Assurance:</label>
<input type="text" class="form-control" name="assaurance" id="cni">
</div>
<div class="form-group">
<label for="cni">Frais de Garde:</label>
<input type="text" class="form-control" name="garde" id="cni">
</div>
<div class="form-group">
<label for="cni">Frais de transport:</label>
<input type="text" class="form-control" name="fraiTransport" id="cni">
</div>
</fieldset>
</div>
<div class="form-group">
<label for="nuveau">Group:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="group">Options</label>
</div>
<select class="custom-select" id="nuveau" name="group">
<option selected>Choose...</option>
#foreach($groups as $group)
<option value="{{$group->id}}">{{$group->group_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="payment">Payment:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="payment">Options</label>
</div>
<select class="custom-select" id="payment" name="paymentD">
<option selected>Choose...</option>
#foreach($payment_dures as $payment_dure)
<option value="{{$payment_dure->id}}">{{$payment_dure->payment_dure_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="dateStart"></label>
<input type="date" class="#" id="dateStart" style="width: 49%;" name="edateStart">
<label for="dateEnd">au:</label>
<input type="date" class="#" id="dateEnd" style="width: 44%;" name="edateEnd">
</div>
<div class="form-group">
<label for="MontantP">Montant paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" name="MontantP" placeholder="" id="MontantP">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<div class="form-group">
<label for="RestP">Rest a paye paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="" id="MontantR" name="RestP">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#multiCollapseExample1" role="button" aria-expanded="false" aria-controls="multiCollapseExample1" style="width: 100%">Bus subscribtion</a>
<div class="row">
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample1">
<div class="card card-body">
<div class="form-group">
<div class="form-group">
<label for="TMontantP">Montant paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="" id="TMontantP" name="TransportP">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<div class="form-group">
<label for="TRestP">Rest a paye paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="" id="TRestP" name="TransportR">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<div class="form-group">
<label for="TdateStart"></label>
<input type="date" class="#" id="TdateStart" style="width: 48%;" name="TdateStart">
<label for="dTateEnd">au:</label>
<input type="date" class="#" id="TdateEnd" style="width: 44%;" name="TdateEnd">
</div>
</div>
</div>
</div>
</div>
</div>
</p>
<br>
<button type="submit" class="btn btn-secondary">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
#else
<div class="d-flex justify-content-center text-center">
<div class="alert alert-danger" role="alert" style="width: 70%">
identifié vous d'abord
</div>
</div>
#endauth
#endif
#endsection
Looks like your foreign key constraint isn't setup correctly. From the look of the error you have setup payment_agrements.responsible_id to point to payment_agrements.id instead of responsibles.id.
In the migration for that table, that field probably looks like this:
$table->foreign('responsible_id')->references('id')->on('payment_agrements');
When it should be:
$table->foreign('responsible_id')->references('id')->on('responsibles');

button not responding laravel

i have this page where i have form where the action url are same. My second form work perfectly fine but mu first form doesn't responding when i hit the button or <a>. I've try to switch the <form action="{{url('purchase')}}" method="post") between form, i've try to cut the action on second form and move it to first form still no luck... any idea? here's sum of my code
<form class="px-2 py-2" action="{{ url('purchase') }}" method="post">
{{csrf_field()}}
<div id="items">
</div>
<div class="row mx-1 px-2">
Purchase
</div>
</form>
that's my first form, inside of id="items" purposely empty since i fill it up with javascript
<form id="newItemForm" style="display:none;">
<div class="form-group row" id="item">
<label for="invoice" class="col-sm-2 col-form-label">Supplier</label>
<div class="col-sm-2">
<select class="form-control" onchange="newExisting(this)">
<option value="#" selected>Choose Supplier</option>
<option value="existing">Existing Supplier</option>
<option value="new">New Supplier</option>
</select>
</div>
<div class="col-sm-8" id="existingCompany" style="display:none;">
<div class="row">
<div class="col-sm-4">
<select class="form-control" name="fromE" onchange="localImport(this)">
<option value="#" checked>From</option>
<option value="f" checked>Import</option>
<option value="l" checked>Local</option>
</select>
</div>
<div class="col-sm-8">
<select class="form-control" name="supplier" id="supplierID">
<option value="#">Choose Company</option>
</select>
</div>
</div>
</div>
<div class="col-sm-8" style="display:none;" id="newCompany">
<div class="row">
<div class="col-sm-4">
<select class="form-control" name="fromN">
<option value="#" checked>From</option>
<option value="f" checked>Import</option>
<option value="l" checked>Local</option>
</select>
</div>
<div class="col-sm-4">
<input type="text" name="kind" value="" placeholder="PT, CV, FIRMA" class="form-control">
</div>
<div class="col-sm-4">
<input type="text" name="supplierName" placeholder="Company Name" class="form-control">
</div>
</div>
</div>
</div>
<div id="newItems">
<div class="form-group row" id="item">
<label for="invoice" class="col-sm-2 col-form-label">Item Name</label>
<div class="col-sm-10">
<input type="text" name="item0" class="form-control" placeholder="Item Name" onkeyup="getCompanyGoods(this)">
<span class="text text-danger" style="display:none;" id="existsWarning0">*Item already exists</span>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="taxInvoice">QTY<span class="text-danger">*</span></label>
<input type="number" name="qty0" class="form-control" id="qty0" required onkeyup="calculate(this)">
</div>
<div class="form-group col-md-3">
<label for="inputPassword4">Units<span class="text-danger">*</span></label>
<input type="number" name="units0" class="form-control" id="units0" required onkeyup="calculate(this)">
</div>
<div class="form-group col-md-3">
<label for="inputPassword4">Total</label>
<div class="form-controll font-weight-bold" style="font-size:x-large;" id="total0">IDR0.00</div>
</div>
</div>
</div>
<label class="btn btn-primary" id="newRow" onclick="addRow()">+ Item</label>
<input type="hidden" name="type" value="new">
<input type="hidden" name="nore" value="#" id="nore">
<input type="number" name="totalItem" value="0" id="totalItem">
<button name="button" class="btn btn-danger float-right" >Purchase</button>
</form>
this is my second form and it work perfectly....
Change
Purchase
to
<button type='submit'>Purchase</button>
Because you have used a tag instead of button type "submit"
Purchase
Change it to like this
<button class="btn btn-primary" type="submit"> Purchase </button>

Checkout Form isn't Submitting

I'm trying to submit the checkout form, but it is not submitting. It has values of products form cart (product name, code, price) and currently entered user data, and screenshot of DB table (orders) https://ibb.co/bbBHCky ...... any solution to resolve it,..........,,,,,,,,.
checkout.blade.php
<ul class="list-group mb-3">
<?php $total_amount = 0; ?>
#foreach($userCart as $cart)
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<h6 class="my-0">{{ $cart->product_name }}</h6>
<small class="text-muted">Quantity: {{ $cart->quantity }}</small>
<small class="text-muted" style="display: none;">{{ $cart->product_code }}</small>
<small class="text-muted" style="display: none;">{{ $cart->product_id }}</small>
</div>
<span class="text-muted">Rs {{ $cart->price }}</span>
</li>
#endforeach
<li class="list-group-item d-flex justify-content-between">
<span>Total (PKR)</span>
<strong>{{ $total }}</strong>
</li>
</ul>
<form method="post" action="{{ url('/checkout') }}" class="needs-validation" novalidate>{{ csrf_field() }}
<div class="row">
<div class="col-md-6 mb-3">
<label for="firstName">Name</label>
<input type="text" name="name" class="form-control" id="firstName" placeholder="name" value="" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
Valid first name is required.
</div>
</div>
</div>
<div class="mb-3">
<label for="email">Email </label>
<input type="email" name="email" class="form-control" id="email" placeholder="you#example.com"
required="required" style="border: 1px solid black !important;">
<div class="invalid-feedback">
Please enter a valid email address for shipping updates.
</div>
</div>
<div class="mb-3">
<label for="address">Address</label>
<input type="text" name="address" class="form-control" id="address" placeholder="1234 Main St" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
Please enter your shipping address.
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="country">Country</label>
<select name="country" class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option value="usa">United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="state">State</label>
<select name="state" class="custom-select d-block w-100" id="state" required>
<option value="">Choose...</option>
<option value="cal">California</option>
</select>
<div class="invalid-feedback">
Please provide a valid state.
</div>
</div>
<div class="col-md-5 mb-3">
<label for="country">City</label>
<select name="city" class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option value="lhr">United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="zip">Zip</label>
<input type="text" name="zipcode" class="form-control" id="zip" placeholder="" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
Zip code required.
</div>
</div>
<div class="col-md-5 mb-3">
<label for="zip">Mobile</label>
<input type="text" name="mobile" class="form-control" id="zip" placeholder="" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
mobile no required.
</div>
</div>
</div>
<button class="btn btn-primary btn-lg btn-block" type="submit" style="background-color: black;">Place Order</button>
</form>
ProductsController
public function placeOrder(Request $request)
{
if ($request->isMethod('post')) {
$data = $request->all();
$session_id = Session::get('session_id');
if (empty($session_id)) {
$session_id = str_random(40);
Session::put('session_id', $session_id);
}
$order = new Order;
$order->id = $id;
$order->name = $name;
$order->email = $email;
$order->address = $address;
$order->country = $country;
$order->state = $state;
$order->city = $city;
$order->zipcode = $zipcode;
$order->mobile = $mobile;
$order->product_id = $product_id;
$order->product_code = $product_code;
$order->product_name = $product_name;
$order->product_price = $product_price;
$order->product_quantity = $qty;
$order->order_status = "New";
$order->grand_total = $data['grand_total'];
$order->save();
return view('products.checkout');
}
}
Route
Route::match(['get','post'],'/place-order','ProductsController#placeOrder');
change form action to
<form method="post" action="{{ url('place-order') }}" class="needs-validation" novalidate>
and remove space from route: '/place- order'
Route::match(['get','post'],'/place-order','ProductsController#placeOrder');

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