this is my blade file
i have 2 problem i want different variable from javascript in this 3 step and in final page i want make a summary of 3 different preset and save to my database like: 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
I want save in my database the information corretct
{{-- has('ordini.id_tipo') ? 'invalid' : '' }}">
{{ trans('cruds.ordini.fields.id_tipo') }}
{{ $errors->first('ordini.id_tipo') }}
{{ trans('cruds.ordini.fields.id_tipo_helper') }}
--}}
{{ trans('global.save') }}
{{ trans('global.cancel') }}
{{----}}
{{--Inizio sessione vecchia, scelta cliente--}}
{{-- STEP 1 --}}
@if ($currentStep == 1)
Farmaci della mattina
has('ordini.cliente_id') ? 'invalid' : '' }}">
{{ trans('cruds.ordini.fields.cliente') }}
listsForFields['cliente']" wire:model="ordini.cliente_id" />
{{ $errors->first('ordini.cliente_id') }}
{{ trans('cruds.ordini.fields.cliente_helper') }}
has('prodotti') ? 'invalid' : '' }}">
{{ trans('cruds.ordini.fields.prodotti') }}
listsForFields['prodotti']" multiple />
{{ $errors->first('prodotti') }}
{{ trans('cruds.ordini.fields.prodotti_helper') }}
Description
@error('description'){{ $message }}@enderror
@endif
{{-- STEP 2 --}}
@if ($currentStep == 2)
Farmaci della pranzo
has('ordini.cliente_id') ? 'invalid' : '' }}">
{{ trans('cruds.ordini.fields.cliente') }}
listsForFields['cliente']" wire:model="ordini.cliente_id" />
{{ $errors->first('ordini.cliente_id') }}
{{ trans('cruds.ordini.fields.cliente_helper') }}
has('prodotti') ? 'invalid' : '' }}">
{{ trans('cruds.ordini.fields.prodotti') }}
listsForFields['prodotti']" multiple />
{{ $errors->first('prodotti') }}
{{ trans('cruds.ordini.fields.prodotti_helper') }}
@endif
{{-- STEP 3 --}}
@if ($currentStep == 3)
Farmaci della sera
has('ordini.cliente_id') ? 'invalid' : '' }}">
{{ trans('cruds.ordini.fields.cliente') }}
listsForFields['cliente']" wire:model="ordini.cliente_id" />
{{ $errors->first('ordini.cliente_id') }}
{{ trans('cruds.ordini.fields.cliente_helper') }}
has('prodotti') ? 'invalid' : '' }}">
{{ trans('cruds.ordini.fields.prodotti') }}
listsForFields['prodotti']" multiple />
{{ $errors->first('prodotti') }}
{{ trans('cruds.ordini.fields.prodotti_helper') }}
@endif
{{-- STEP 4 --}}
@if ($currentStep == 4)
STEP 4/4 - Attachments
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!
CV
@error('cv'){{ $message }}@enderror
You must agree with our Terms and Conditions
@error('terms'){{ $message }}@enderror
@endif
@if ($currentStep == 1)
@endif
@if ($currentStep == 2 || $currentStep == 3 || $currentStep == 4)
Back
@endif
@if ($currentStep == 1 || $currentStep == 2 || $currentStep == 3)
Next
@endif
@if ($currentStep == 4)
Submit
@endif
my controller:
<?php
namespace AppHttpLivewireOrdini;
use AppModelsCustomer;
use AppModelsOrdini;
use AppModelsProduct;
use LivewireComponent;
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();
}
}
and my other blade select list
<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>
i have 2 problem i want different variable from javascript in this 3 step and in final page i want make a summary of 3 different preset and save to my database like: 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
I want save in my database the information corretct