I have 2 method in 1 blade, Delete and PUT, if i want delete it's work, but if I save info updated and I use method PUT, drop error: The DELETE method is not supported for this route. Supported methods: GET, HEAD, PUT., I use form collective composer for form.
SAVE Button not working, drop error, Remove button working good.
<div class="container-fluid mt--7">
<div class="row">
<div class="col-xl-12">
{!! Form::open(['action' => ['InvoiceController#update', $invoice->id], 'method' => 'POST']) !!}
{{csrf_field()}}
<div class="card bg-secondary shadow">
<div class="card-header bg-white border-0">
<div class="row align-items-center">
<div class="col-8">
<h3 class="mb-0">Edit {{$invoice->number}} invoice </h3>
</div>
<div class="col-4 text-right">
{{ Form::submit('Save', ['class' => 'btn btn-sm btn-primary']) }}
{{ Form::hidden('_method', 'PUT') }}
</div>
</div>
</div>
<div class="card-body">
<div class="pl-lg-4">
<div class="row">
<div class="col-lg-4">
<div class="form-group">
<label class="form-control-label">Company</label>
<select class="form-control form-control-alternative" name="company_id" required>
<option value="{{$invoice->company_id}}" selected>{{ $invoice->company_name->Name }}</option>
#foreach($companys as $company)
<option value="{{$company->id}}">{{ $company->Name }}</option>
#endforeach
</select>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label class="form-control-label">Payment</label>
<select class="form-control form-control-alternative" name="payment" required>
<option value="{{$invoice->payment}}" selected>{{$invoice->payment}}</option>
<option value="Pending">Pending</option>
<option value="Paid">Paid</option>
<option value="Canceled">Canceled</option>
</select>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<label class="form-control-label">Invoices number</label>
<input class="form-control form-control-alternative" type="text" value="{{$invoice->number}}" disabled>
<input class="form-control form-control-alternative" name="number" placeholder="Auto generated" type="text" value="{{$invoice->number}}" hidden>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="form-control-label">Date</label>
<input class="form-control form-control-alternative datepicker-here" name="date" data-language='en' placeholder="Select date" type="text" value="{{$invoice->date}}">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-control-label">Due date</label>
<input class="form-control form-control-alternative datepicker-here" name="due_date" data-language='en' placeholder="Select date" type="text" value="{{$invoice->due_date}}">
</div>
</div>
</div>
<hr class="my-4" />
<div class="row">
<div class="col-lg-12">
<table class="table table-bordered" id="dynamic_field">
<thead>
<tr>
<th scope="col">No.</th>
<th scope="col">Description</th>
<th scope="col">Qty</th>
<th scope="col">Price</th>
<th scope="col">Amount</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
#if(count($invoice_lists) > 0)
<?php $no = 1; ?>
#foreach( $invoice_lists as $invoice_list )
<tr>
<td>
{{ $no }}
<input type="text" name="list_id[]" value="{{ $invoice_list->id }}" hidden>
</td>
<td><input class="form-control form-control-alternative" type="text" name="description[]" value="{{$invoice_list->desc}}" placeholder="Description"></td>
<td><input class="form-control form-control-alternative qty" type="text" name="qty[]" value="{{$invoice_list->qty}}" placeholder="Qty"></td>
<td><input class="form-control form-control-alternative price" type="text" name="price[]" value="{{$invoice_list->price}}" placeholder="Price"></td>
<td><input class="form-control form-control-alternative amount" type="text" name="amount[]" value="{{$invoice_list->amount}}" placeholder="Amount"></td>
<td>
#if ($no == 1)
{!! Form::open(['action' => ['InvoiceController#remove', $invoice_list->id, $invoice->id], 'method' => 'POST']) !!}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Remove', ['class' => 'btn btn-danger btn-sm', 'disabled']) }}
{!! Form::close() !!}
#else
{!! Form::open(['action' => ['InvoiceController#remove', $invoice_list->id, $invoice->id], 'method' => 'POST']) !!}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Remove', ['class' => 'btn btn-danger btn-sm']) }}
{!! Form::close() !!}
#endif
</td>
<?php $no++; ?>
</tr>
#endforeach
#else
....
#endif
</tbody>
<thead>
<tr>
<th colspan="2"></th>
<th scope="col"><b>Sub Total</b></th>
<th scope="col"><b>VAT(21%)</b></th>
<th scope="col"><b>Grand Total</b></th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2"></th>
<td scope="col">
<input class="form-control form-control-alternative sub" value="{{$invoice->sub}}" disabled>
<input class="form-control form-control-alternative subhidden" name="subhidden" value="{{$invoice->sub}}" hidden>
</td>
<td scope="col">
<input class="form-control form-control-alternative vat" value="{{$invoice->vat}}" disabled>
<input class="form-control form-control-alternative vathidden" name="vathidden" value="{{$invoice->vat}}" hidden>
</td>
<td scope="col">
<input class="form-control form-control-alternative grand" value="{{$invoice->grand}}" disabled>
<input class="form-control form-control-alternative grandhidden" name="grandhidden" value="{{$invoice->grand}}" hidden>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr class="my-4" />
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label class="form-control-label">Terms and Conditions</label>
<textarea class="form-control form-control-alternative" name="terms" rows="5" placeholder="Terms and Conditinios" required>{{$invoice->terms}}</textarea>
</div>
</div>
</div>
<input type="text" name="id" value="{{$invoice->id}}" hidden>
</div>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
You have multiple forms in 1 form, this is not actually good idea, but if it is critically required to have so, you have to give unique id attribute to each form and also set form="currentFormId" to the form's inputs
Related
When creating an order I need to redirect to a new page to enter the information of ordered materials and store the pivot(order, material), but when I submitted the form on the second page the request element detected empty and I can't recovery my inputs values to store it, I don't understand why it doesn't work
the form code :
<form class="form-material" action="{{ route('commandeMateriaus.store') }}" method="POST">
#csrf
<div style="margin-bottom: 20px; color:black;">
<div style="padding-right: 50px;">
<div >
<span style="margin-right: 50px;"> <span style="font-weight: bold;"> Code de la commande : </span><input type="text" name="code_commande" value="{{ $commande->code_commande }}" style="border:none;" readonly> </span>
</div>
<span style="margin-right: 50px;"> <span style="font-weight: bold;"> Date de la commande : </span> {{ $commande->date_commande }} </span>
<span style="margin-right: 50px;"> <span style="font-weight: bold;"> Fournisseur : </span> {{ $fournisseur->intitule_fournisseur }}</span>
</div>
</div>
<div style="margin-bottom: 20px;">
<div class="row">
<div class="col-6">
<div class="form-group form-primary form-static-label">
<label class="form-label " style="top: -14px; color: black;">Matériaux <span class="text-danger">*</span> </label>
<div class="select">
<select id="mySelect" class="materiaux form-control" name="materiaus[]" multiple size="5">
#foreach($materiaus as $materiau)
<option value="{{ $materiau->id }}"> {{ $materiau->intitule_materiau }} </option>
#endforeach
</select>
</div>
<span class="form-bar"></span>
</div>
</div>
</div>
</div>
<div>
<h5>Liste des matériaux commandés :</h5>
<table class="table m-b-0 text-center">
<thead>
<td>Matériau</td>
<td>Prix Unitaire</td>
<td>Quantité</td>
<td>Montant</td>
</thead>
<tbody >
#foreach($materiaus as $materiau)
<tr style="display:none;" id="{{ $materiau->id }}" class="data">
<td > {{ $materiau->intitule_materiau }} </td>
<td> <input type="text" id="prix{{ $materiau->id }}" name="prix_unit_materiau" value="{{ $materiau->prix_unit_materiau }}" style="border:none;" readonly> </td>
<td > <input type="number" class="quantite" id="q{{ $materiau->id }}" name="quantite_materiau" style="border:none;" placeholder="Entrer la quantité" onchange="recupValeur(this.value, this.id);"> </td>
<td ><input type="decimal" class="montant" id="montant{{ $materiau->id }}" name="montant_materiau" value="0" style="border:none;" readonly></td>
</tr>
#endforeach
<tr>
<td colspan="4" style="text-align:right;" >Total</td>
<td ><input type="decimal" name="total_commande" value="0" style="border:none;" id="total" readonly></td>
</tr>
</tbody>
</table>
</div>
<div class=" text-right" style="margin-top: 10px;">
<button type="submit" class="btn btn-primary"> <i class="fa fa-fw fa-plus-circle" > </i> Ajouter</button>
<button type="reset" class="btn btn-info" style="margin-left: 10px;"><i class="fa fa-fw fa-sync" ></i> Réinitialiser</button>
</div>
</form>
the store method
public function store(Request $request)
{
$request->validate([
'code_commande' => 'required',
'materiaus' => 'required',
'quantite_materiau' => 'required',
'montant_materiau' => 'required',
'total_commande' => 'required'
]);
$cm = new CommandeMateriau();
$commande = Commande::where('code_commande', '=', $request->code_commande)->first();
$commande_id = $commande->id;
$commande->total_commande = $request->total_commande;
$commande->save();
$cm->commande_id = $commande_id;
$cm->quantite_materiau = $request->quantite_materiau;
$cm->montant_materiau = $request->montant_materiau;
foreach ($request->materiaus as $materiau){
$cm->materiau_id = $materiau->id;
$cm->save();
}
return redirect()->back()
->with('success','Enregistrement ajouté avec succes.');
}
Can someone help me, please
Because you have an input type of array, try to add this enctype="multipart/form-data" inside your form tag.
<form class="form-material" action="{{ route('commandeMateriaus.store') }}" method="POST" enctype="multipart/form-data" >
hello i need to do an update inside a model using Laravel, the problem is when i click on the update button (his name in the code is Modifier) the page is not refreshing.
i have tried to work with an a tag in place of button .and with the a tag the page refresh but my data is not updating.
can someone tell me where is the problem in the code
the index view code :
<table class="table table-bordered table-left">
<thead>
<tr>
<th>#</th>
<th>Nom</th>
<th>Email</th>
<th>Rôle</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($users as $key=>$user)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
#if ($user->is_admin==1)Administrateur
#else Caissier
#endif
</td>
<td>
<div class="btn-group">
<a class="btn btn-success" href="" data-toggle="modal" data-target="#edituser{{ $user->id }}">
<i class="fas fa-edit"></i>
</a>
<a href="" class="btn btn-danger">
<i class="fas fa-trash"></i>
</a>
</div>
</td>
</tr>
{{-- edit model --}}
<div class="modal right fade" id="edituser{{ $user->id }}" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="staticBackdropLabel">Modifier l'utilisateur</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('users.update', $user->id) }}" method="post">
#csrf
#method('put')
<div class="form-group">
<label for="name">Nom</label>
<input type="text" value="{{ $user->name }}" name="name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" value="{{ $user->email }}" name="email" class="form-control">
</div>
<div class="form-group">
<label for="name">Mot de passe</label>
<input type="password" readonly name="password" value="{{ $user->password }}" class="form-control">
</div>
{{-- <div class="form-group">
<label for="name">Confirmer le mot de passe</label>
<input type="password" name="confirm_password" class="form-control">
</div> --}}
<div class="form-group">
<label for="name">Rôle</label>
<select name="is_admin" id="" class="form-control">
<option value="1" #if ($user->is_admin==1)
selected
#endif>Administrateur</option>
<option value="2" #if ($user->is_admin==2)
selected
#endif>Caissier</option>
</select>
</div>
<div >
<button class="btn btn-success btn-block">Modifier</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endforeach
</tbody>
</table>
the controller code :
public function update(Request $request, $id)
{
$users = User::find($id);
if (!$users) {
return back()->with('Error','user created');
}
$users->update($request->all());
return back()->with('Success','user created');
}
Your button
<button class="btn btn-success btn-block">Modifier</button>,
should be
<button class="btn btn-success btn-block" type="submit">Modifier</button> in order to submit the form to your controller.
In Laravel-5.8 project, I am working on dynamic input form.
The main model is AppraisalGoal while the second model is AppraisalGoalDetail
Controller
public function create()
{
$goal = new AppraisalGoal();
$goaldetail = new AppraisalGoalDetail();
return view('appraisal.appraisal_goals.create')
->with('goal', $goal)
->with('goaldetail', $goaldetail) ;
}
public function store(StoreAppraisalGoalRequest $request)
{
DB::beginTransaction();
try {
$goal = new AppraisalGoal();
$goal->weighted_score = $request->weighted_score;
$goal->goal_title = $request->goal_title;
$goal->goal_description = $request->goal_description;
if ($request->appraisal_doc != "") {
$appraisal_doc = $request->file('appraisal_doc');
$new_name = rand() . '.' . $appraisal_doc->getClientOriginalExtension();
$appraisal_doc->move(public_path('storage/documents/appraisal_goal'), $new_name);
$goal->appraisal_doc = $new_name;
}
$goal->save();
foreach ( $request->activity as $key => $activity){
$startDate = Carbon::parse($request->start_date[$key]);
$endDate = Carbon::parse($request->end_date[$key]);
$insert_array = [
'kpi_description' => $request->kpi_description[$key],
'activity' => $request->activity[$key],
'start_date' => $startDate ->toDateTimeString(),
'end_date' => $endDate->toDateTimeString(),
];
AppraisalGoalDetail::create($insert_array );
}
DB::commit();
Session::flash('success', 'Goal is created successfully');
return redirect()->route(goals.index');
} catch (Exception $exception) {
DB::rollback();
Session::flash('error', 'Action failed! Please try again');
return redirect()->route('goals.index');
}
}
the create.blade view is shown below
<form action="{{route('goals.store')}}" method="post" class="form-horizontal" enctype="multipart/form-data">
{{csrf_field()}}
<div class="card-body">
<div class="form-body">
<div class="row">
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Goal Title:<span style="color:red;">*</span></label>
<input type="text" name="goal_title" value="{{ old('goal_title', $goal->goal_title) }}" placeholder="Enter goal title here" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label>Goal Description</label>
<textarea rows="2" name="goal_description" class="form-control" value="{{old('goal_description',$goal->goal_description)}}" placeholder="Enter Goal Description here ...">{{old('goal_description',$goal->goal_description)}}</textarea>
</div>
</div>
<div class="col-sm-12">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Activity<span style="color:red;">*</span></th>
<th scope="col">KPI<span style="color:red;">*</span></th>
<th scope="col">Start Date<span style="color:red;">*</span></th>
<th scope="col">End Date<span style="color:red;">*</span></th>
<th scope="col"><a class="btn btn-info addRow"><i class="fa fa-plus"></i></a></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="activity[]" class="form-control activity" ></td>
<td><input type="text" name="kpi_description[]" class="form-control kpi_description" ></td>
<td><input type="date" class="form-control start_date" placeholder="dd/mm/yyyy" name="start_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>
<td><input type="date" class="form-control end_date" placeholder="dd/mm/yyyy" name="end_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>
<td><a class="btn btn-danger remove"> <i class="fa fa-times"></i></a></td>
</tr>
</tbody>
</table>
</div>
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Weight(%):<span style="color:red;">*</span></label>
<input type="number" name="weighted_score" placeholder="Enter weighted score here" class="form-control" max="120">
</div>
</div>
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Attachment:</label>
<div class="custom-file">
<input value="{{old('appraisal_doc',$goal->appraisal_doc)}}" type="file" name="appraisal_doc" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">{{ trans('global.save') }}</button>
</div>
</form>
AppraisalGoal is foreignkey to AppraisalGoalDetail. AppraisalGoalDetail is an Array.
The way the application operates is that, When the user clicks the submit button, the application saves into AppraisalGoal and pick its id and saves it with the other data into AppraisalGoalDetail.
However, the validation is giving issue. Whenever the user submits and the page is validated, all went blank upon showing the error page, meaning that I need to input them all over again.
I was able to resolve these ones that belong to AppraisalGoal model by using old() help function and it works:
<div class="col-12 col-sm-6">
<div class="form-group">
<label class="control-label"> Goal Title:<span style="color:red;">*</span></label>
<input type="text" name="goal_title" value="{{ old('goal_title', $goal->goal_title) }}" placeholder="Enter goal title here" class="form-control">
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label>Goal Description</label>
<textarea rows="2" name="goal_description" class="form-control" value="{{old('goal_description',$goal->goal_description)}}" placeholder="Enter Goal Description here ...">{{old('goal_description',$goal->goal_description)}}</textarea>
</div>
</div>
I don't know how to resolve these ones that belong to AppraisalGoalDetail:
<tr>
<td><input type="text" name="activity[]" class="form-control activity" ></td>
<td><input type="text" name="kpi_description[]" class="form-control kpi_description" ></td>
<td><input type="date" class="form-control start_date" placeholder="dd/mm/yyyy" name="start_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>
<td><input type="date" class="form-control end_date" placeholder="dd/mm/yyyy" name="end_date[]" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}"></td>
<td><a class="btn btn-danger remove"> <i class="fa fa-times"></i></a></td>
</tr>
How do I get this corrected that the page should still retain the data after submit and validation error?
Thank you
When You get Validation Error & something fault in server..You redirect the page & withInput() function like this..
return redirect()->route('goals.index')->withInput(['goal_title' => $request->goal_title, 'goal_description' => $request->goal_description]);
It will sork & show your value which you give to update
In My list view I have all the details of leave. But when I click on details It will display me a Pop-up. In Pop up box it has to fetch and give me all the details of particular field but instead of that it always give me details of last inserted record
Here Is code of my list file
<table id="myTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Employee Name</th>
<th>Leave Type</th>
<th>Leave Duration</th>
<th>Applied On</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#if($allLeaves != null)
#foreach($allLeaves as $leave)
<tr>
<td> {{ $leave->username }} </td>
<td> {{ $leave->typeOfLeave }} </td>
<td>
{{ $leave->startDate }} To
{{ $leave->endDate }}
</td>
<td> {{ $leave->startDate }} </td>
<td>
#if($leave['status']=='Pending')
<span class="btn btn-warning">Pending</span>
#elseif($leave['status']=='Approved')
<span class="btn btn-success">Approved</span>
#else
<span class="btn btn-danger">Rejected</span>
#endif
</td>
<td>Details</td>
</tr>
</tbody>
</table>
and in same page i wrote code of fetch records
<form id="myform" class="form-horizontal" method="POST" action="{{ route('approve_leave', $leave->id) }}">
#csrf
<div class="card-body">
<div class="row">
<label class="col-md-6"><strong> Employee Name</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="emp_name" disabled value="{{$leave->username}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Leave Type</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="leavetype" disabled value="{{$leave->typeOfLeave}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Leave Duration</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="leaveduration" disabled value="{{ $leave->startDate }} To {{ $leave->endDate }}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Reason</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="reason" disabled value="{{$leave->reasonForLeave}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Applied on</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="appliedon" disabled value="{{$leave->startDate}}" style="border:none">
</div>
</div>
<br>
<div class="row">
<label class="col-md-6"><strong>Action</strong></label>
<div class="col-md-6">
<select class="form-control" id="status" name="status" value="{{$leave->status}}">
<option value="Pending" selected="selected">Pending</option>
<option value="Approved">Approved</option>
<option value="Rejected">Rejected</option>
</select>
</div>
</div>
#endforeach
<br>
<div class="row">
<label class="col-md-6"><strong>Reason For Action</strong></label>
<div class="col-md-6">
<input type="text" class="form-control" id="reason" name="reasonForAction" placeholder="Reason Of Action" style="border:none">
</div>
</div>
<br>
<div class="modal-footer">
<button type="submit" class="btn btn-info waves-effect" data-dismiss="modal">Save</button>
<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Cancel</button>
</div>
</div>
</form>
And This is the code i wrote in controller file
//Code Of list view
public function listOfLeave()
{
$allLeaves = LeaveManagement::all();
return view('pages.leavelist', compact('allLeaves'));
}
//Code of click on details button and fetch record of that particular id
public function handleLeave($id)
{
$leave = LeaveManagement::find($id);
return view('pages.leavelist', compact('leave', 'id'));
}
//code of approve reject leave and change the status of leave
public function approveLeave(Request $request ,$id)
{
$leave = LeaveManagement::find($id);
$leave->status = $request->get('status');
$leave->reasonForAction = $request->get('reasonForAction');
$leave->save();
return view('pages.leavelist');
}
If you want to show data according to user's id then you have to pass each field like data-fieldname and then you can fetch that field's data as shown in script.
Button:
<button type="button"
class="btn btn-xs btn-default confirm-modal"
data-toggle="modal"
data-target="#model"
data-id="{{ $singleRecord->id }}"
data-name="{{ $singleRecord->full_name }}"
data-leave_reason="{{ $singleRecord->leave_reason }}"
data-from_date="{{ date('d-F-Y', strtotime($singleRecord->from_date)) }}"
data-to_date="{{ date('d-F-Y', strtotime($singleRecord->to_date)) }}"
>Details </button>
And add script
<script type="text/javascript">
$('.confirm-modal').click(function (event) {
$('.employee_name').text($(this).data('name'));
$('#from_date').text($(this).data('from_date'));
$('#to_date').text($(this).data('to_date'));
$('#total_leaves').text($(this).data('total_leaves'));
$('.leave_reason').text($(this).data('leave_reason'));
})
</script>
In model div, add each id to display that data.
<div class="col-md-12">
<label for="to_date">To Date:</label>
<span id="to_date"></span>
Hope this helps :)
Edit your modal button and modal id like below,
<td>Details</td>
and your modal,
<div id="details_{{ $leave->id }}" class="modal fade edit-form" role="dialog">
or you can use javascript to populate your field,
<button type="button" class="btn btn-xs btn-default confirm-modal" data-toggle="modal" data-target="#details"
data-leave="{{ $leave }}">Details </button>
<script type="text/javascript">
$(document).on('click', '.confirm-modal', function(e){
var data = $(this).data('leave');
$('#emp_name').text(data.username);
$('#from_date').text(data.from_date');
$('#to_date').text(data.to_date);
$('#total_leaves').text(data.total_leaves);
$('#leave_reason').text(data.leave_reason);
})
</script>
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