bounty将在5天后过期。回答此问题可获得+50的声誉奖励。Nu Carvignulu正在寻找来自声誉良好来源的答案。
这是我的刀片文件,我有2个问题,我想从javascript在这3个步骤不同的变量,并在最后一页,我想做一个总结3个不同的预设,并保存到我的数据库一样:
id_client: = 1 ; order_1d =1 sub_order = 1
id_client: = 1 ; order_1d =1 sub_order = 2
id_client: = 1 ; order_1d =1 sub_order = 3
我想保存在我的数据库中的信息corretct我可能有2个选项:
1.每次我转到下一页时都会保存
1.我在最后保存,但我不知道如何区分来自javascript函数的变量
<pre>
<form wire:submit.prevent="submit" class="pt-3">
<div>
{{-- <div class="form-group {{ $errors->has('ordini.id_tipo') ? 'invalid' : '' }}">
<label class="form-label" for="id_tipo">{{ trans('cruds.ordini.fields.id_tipo') }}</label>
<input class="form-control" type="number" name="id_tipo" id="id_tipo" wire:model.defer="ordini.id_tipo" step="1">
<div class="validation-message">
{{ $errors->first('ordini.id_tipo') }}
</div>
<div class="help-block">
{{ trans('cruds.ordini.fields.id_tipo_helper') }}
</div>
</div>--}}
<div class="form-group">
<button class="btn btn-indigo mr-2" type="submit">
{{ trans('global.save') }}
</button>
<a href="{{ route('admin.ordinis.index') }}" class="btn btn-secondary">
{{ trans('global.cancel') }}
</a>
</div>
{{--</form>--}}
{{--Inizio sessione vecchia, scelta cliente--}}
</form>
<form>
{{-- STEP 1 --}}
@if ($currentStep == 1)
<div class="step-one">
<div class="card">
<div class="card-header text-xl text-pink-400">Farmaci della mattina</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group {{ $errors->has('ordini.cliente_id') ? 'invalid' : '' }}">
<label class="form-label" for="cliente">{{ trans('cruds.ordini.fields.cliente') }}</label>
<x-select-list class="form-control" id="cliente" name="cliente" :options="$this->listsForFields['cliente']" wire:model="ordini.cliente_id" />
<div class="validation-message">
{{ $errors->first('ordini.cliente_id') }}
</div>
<div class="help-block">
{{ trans('cruds.ordini.fields.cliente_helper') }}
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group {{ $errors->has('prodotti') ? 'invalid' : '' }}">
<label class="form-label" for="prodotti">{{ trans('cruds.ordini.fields.prodotti') }}</label>
<x-select-list class="form-control" id="prodotti" name="prodotti" wire:model="prodotti" :options="$this->listsForFields['prodotti']" multiple />
<div class="validation-message">
{{ $errors->first('prodotti') }}
</div>
<div class="help-block">
{{ trans('cruds.ordini.fields.prodotti_helper') }}
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="">Description</label>
<textarea class="form-control" cols="2" rows="2" wire:model="description"></textarea>
<span class="text-danger">@error('description'){{ $message }}@enderror</span>
</div>
</div>
</div>
</div>
@endif
{{-- STEP 2 --}}
@if ($currentStep == 2)
<div class="step-two">
<div class="card">
<div class="card-header text-xl text-pink-400">Farmaci della pranzo</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group {{ $errors->has('ordini.cliente_id') ? 'invalid' : '' }}">
<label class="form-label" for="cliente">{{ trans('cruds.ordini.fields.cliente') }}</label>
<x-select-list class="form-control" id="cliente" name="cliente" :options="$this->listsForFields['cliente']" wire:model="ordini.cliente_id" />
<div class="validation-message">
{{ $errors->first('ordini.cliente_id') }}
</div>
<div class="help-block">
{{ trans('cruds.ordini.fields.cliente_helper') }}
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group {{ $errors->has('prodotti') ? 'invalid' : '' }}">
<label class="form-label" for="prodotti">{{ trans('cruds.ordini.fields.prodotti') }}</label>
<x-select-list class="form-control" id="prodotti" name="prodotti" wire:model="prodotti" :options="$this->listsForFields['prodotti']" multiple />
<div class="validation-message">
{{ $errors->first('prodotti') }}
</div>
<div class="help-block">
{{ trans('cruds.ordini.fields.prodotti_helper') }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endif
{{-- STEP 3 --}}
@if ($currentStep == 3)
<div class="step-three">
<div class="card">
<div class="card-header text-xl text-pink-400">Farmaci della sera</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group {{ $errors->has('ordini.cliente_id') ? 'invalid' : '' }}">
<label class="form-label" for="cliente">{{ trans('cruds.ordini.fields.cliente') }}</label>
<x-select-list class="form-control" id="cliente" name="cliente" :options="$this->listsForFields['cliente']" wire:model="ordini.cliente_id" />
<div class="validation-message">
{{ $errors->first('ordini.cliente_id') }}
</div>
<div class="help-block">
{{ trans('cruds.ordini.fields.cliente_helper') }}
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group {{ $errors->has('prodotti') ? 'invalid' : '' }}">
<label class="form-label" for="prodotti">{{ trans('cruds.ordini.fields.prodotti') }}</label>
<x-select-list class="form-control" id="prodotti" name="prodotti" wire:model="prodotti" :options="$this->listsForFields['prodotti']" multiple />
<div class="validation-message">
{{ $errors->first('prodotti') }}
</div>
<div class="help-block">
{{ trans('cruds.ordini.fields.prodotti_helper') }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endif
{{-- STEP 4 --}}
@if ($currentStep == 4)
<div class="step-four">
<div class="card">
<div class="card-header bg-secondary text-white">STEP 4/4 - Attachments</div>
<div class="card-body">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Itaque delectus officia inventore id facere at aspernatur ad corrupti asperiores placeat, fugiat tempora soluta optio recusandae eligendi impedit ipsam ullam amet!
<div class="form-group">
<label for="cv">CV</label>
<input type="file" class="form-control" wire:model="cv">
<span class="text-danger">@error('cv'){{ $message }}@enderror</span>
</div>
<div class="form-group">
<label for="terms" class="d-block">
<input type="checkbox" id="terms" wire:model="terms"> You must agree with our <a href="#">Terms and Conditions</a>
</label>
<span class="text-danger">@error('terms'){{ $message }}@enderror</span>
</div>
</div>
</div>
</div>
@endif
<div class="action-buttons d-flex justify-content-between bg-white pt-2 pb-2">
@if ($currentStep == 1)
<div></div>
@endif
@if ($currentStep == 2 || $currentStep == 3 || $currentStep == 4)
<button type="button" class="btn btn-md btn-secondary" wire:click="decreaseStep()">Back</button>
@endif
@if ($currentStep == 1 || $currentStep == 2 || $currentStep == 3)
<button type="button" class="btn btn-md btn-success" wire:click="increaseStep()">Next</button>
@endif
@if ($currentStep == 4)
<button type="submit" class="btn btn-md btn-primary">Submit</button>
@endif
</div>
</form>
</div>
</pre>
我的控制器:
<?php
namespace App\Http\Livewire\Ordini;
use App\Models\Customer;
use App\Models\Ordini;
use App\Models\Product;
use Livewire\Component;
class Create extends Component
{
public Ordini $ordini;
public array $prodotti = [];
public array $listsForFields = [];
public $totalSteps = 4;
public $currentStep = 1;
public function mount(Ordini $ordini)
{
$this->ordini = $ordini;
$this->initListsForFields();
}
public function render()
{
return view('livewire.ordini.create');
}
public function submit()
{
$this->validate();
$this->ordini->save();
$this->ordini->prodotti()->sync($this->prodotti);
return redirect()->route('admin.ordinis.index');
}
public function increaseStep(){
$this->resetErrorBag();
$this->validate();
$this->currentStep++;
if($this->currentStep > $this->totalSteps){
$this->currentStep = $this->totalSteps;
}
}
public function decreaseStep(){
$this->resetErrorBag();
$this->currentStep--;
if($this->currentStep < 1){
$this->currentStep = 1;
//render();
}
}
protected function rules(): array
{
return [
'ordini.name' => [
'string',
'nullable',
],
'ordini.cliente_id' => [
'integer',
'exists:customers,id',
'nullable',
],
'prodotti' => [
'array',
],
'prodotti.*.id' => [
'integer',
'exists:products,id',
],
'ordini.id_tipo' => [
'integer',
'min:-2147483648',
'max:2147483647',
'nullable',
],
];
}
protected function initListsForFields(): void
{
$this->listsForFields['cliente'] = Customer::pluck('name', 'id')->toArray();
$this->listsForFields['prodotti'] = Product::pluck('name', 'id')->toArray();
}
}
和我的另一个刀片选择列表
<pre>
<div>
<div wire:ignore class="w-full">
@if(isset($attributes['multiple']))
<div id="{{ $attributes['id'] }}-btn-container" class="mb-3">
<button type="button" class="btn btn-info btn-sm select-all-button">{{ trans('global.select_all') }}</button>
<button type="button" class="btn btn-info btn-sm deselect-all-button">{{ trans('global.deselect_all') }}</button>
</div>
@endif
<select class="select2 form-control" data-placeholder="{{ __('Select your option') }}" {{ $attributes }}>
@if(!isset($attributes['multiple']))
<option></option>
@endif
@foreach($options as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</div>
</div>
@push('scripts')
<script>
document.addEventListener("livewire:load", () => {
let el = $('#{{ $attributes['id'] }}')
let buttonsId = '#{{ $attributes['id'] }}-btn-container'
function initButtons() {
$(buttonsId + ' .select-all-button').click(function (e) {
el.val(_.map(el.find('option'), opt => $(opt).attr('value')))
el.trigger('change')
})
$(buttonsId + ' .deselect-all-button').click(function (e) {
el.val([])
el.trigger('change')
})
}
function initSelect () {
initButtons()
el.select2({
placeholder: '{{ __('Select your option') }}',
allowClear: !el.attr('required')
})
}
initSelect()
Livewire.hook('message.processed', (message, component) => {
initSelect()
});
el.on('change', function (e) {
let data = $(this).select2("val")
if (data === "") {
data = null
}
@this.set('{{ $attributes['wire:model'] }}', data)
});
});
</script>
@endpush
</pre>
我有2个问题,我想从javascript在这3个步骤不同的变量,并在最后一页,我想做一个总结3个不同的预设和保存到我的数据库一样:
id_client: = 1 ; order_1d =1 sub_order = 1
id_client: = 1 ; order_1d =1 sub_order = 2
id_client: = 1 ; order_1d =1 sub_order = 3
我想在我的数据库中保存正确的信息
这是我的创建顺序,与按钮下一个我做另一个页面,该页面是相同的。我想3哦这些。在最后一页我想所有的信息
1条答案
按热度按时间q8l4jmvw1#