Jan 31, 2022
0
Level 1
Save Session in multi step form
I follow this https://5balloons.info/multi-page-step-form-in-laravel-with-validation/ to create a multi step form. I try to save all inputs in Session and at end save in DB. I want, if i back to last step, The fields are filled with the data already given. But when i back, it gives me just number 1 in every field, that i gieved some data.
thanks for any help. that is my Controller:
public function createStepTwo(Request $request)
{
$register = $request->session()->get('register');
$countries = CountryListFacade::getList('en');
return view('wizard.step_two', compact('countries'), compact('register', $register));
}
public function createTwo(Request $request)
{
$data = $request->validate([
'another' => '',
'name' => 'required',
'address_one' => 'required',
'address_two' => 'string|nullable',
'zip' => 'required|numeric',
'city' => 'required',
'state' => 'string',
'country' => 'required',
]);
auth()->user()->company()->create($data);
// $company_id = auth()->user()->company()->id;
// DB::table('users')->where('id', auth()->id())->update(['company_id' => $company_id]);
if (empty($request->session()->get('product'))) {
$register = new Companies();
$register->fill($data);
$request->session()->put('register', $register);
} else {
$register = $request->session()->get('register');
$register->fill($data);
$request->session()->put('register', $register);
}
return dd($register);
//return redirect('/step_three');
}
that my blade:
<div class="two-account-setup-2">
<div class="two-navigation-icons">
<a href=" {{ route('step_one') }}" class="two-backicon">
<img alt="" class="two-vector" src="https://static.overlay-tech.com/assets/f37996f4-4702-42c3-a453-1efaa4666126.svg" />
</a>
</div>
<img alt="" class="two-independesk-logo" src="https://static.overlay-tech.com/assets/8e30a44f-b89a-4d36-86e1-65bc733ab54c.svg" />
<form method="POST" action="{{ route('step_two') }}">
@csrf
@if($errors->any())
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
@endif
<div class="two-description">
<div class="two-progress-bar">
<p class="two-progress-status">{{__('Settings')}}</p>
<p class="two-progress-status-two">{{__('Step:')}} 2 {{__('of')}} 5</p>
</div>
<p class="two-setup1-description">
{{__('Please enter your company data:')}}
</p>
</div>
<div class="two-input-container">
<div class="two-companyname-input">
<p class="two-fieldlabel-companyname">{{__('Company name')}}</p>
<input class="two-field" placeholder="{{__('Company name')}}" name="name" value="{{ $register->name or '' }}" />
</div>
<div class="two-companyname-input">
<p class="two-fieldlabel-companyname">{{__('Address 1')}}</p>
<input class="two-field-two" placeholder="{{__('Address 1')}}" name="address_one" value="{{ $register->address_one or '' }}" />
</div>
<div class="two-companyname-input">
<p class="two-fieldlabel-companyname">{{__('Address 2')}}</p>
<input class="two-field-two" placeholder="{{__('Address 2')}}" name="address_two" value="{{ $register->address_two or '' }}" />
</div>
<div class="two-companyname-input">
<p class="two-fieldlabel-companyname">{{__('Zip code')}}</p>
<input class="two-field-three" placeholder="{{__('Zip code')}}" name="zip" value="{{ $register->zip or '' }}" />
</div>
<div class="two-companyname-input">
<p class="two-fieldlabel-companyname">{{__('City')}}</p>
<input class="two-field-three" placeholder="{{__('City')}}" name="city" value="{{ $register->city or '' }}" />
</div>
<div class="two-state-input">
<p class="two-fieldlabel-state">{{__('State')}}</p>
<input class="two-field-three" placeholder="{{__('State')}}" name="state" value="{{ $register->state or '' }}" />
</div>
<div class="two-country-input">
<p class="two-fieldlabel-country">{{__('Country')}}</p>
<div class="two-field-wrapper">
<select class="two-field-four" name="country">
<option value="">{{__('Country')}}</option>
@foreach ($countries as $country)
<option value="{{ $country }}">{{ $country }}</option>
@endforeach
</select>
</div>
</div>
</div>
<div class="two-buttons">
<a style="text-decoration: none;" href=" {{ route('step_one') }}">
<button type="button" class="one-back">
<p class="one-label-three">{{__('Back')}}</p>
</button>
</a>
<button type="submit" class="continue">
<p class="label-two">{{__('Next')}}</p>
</button>
</div>
</form>
</div>
and that is my output dd($register):
App\Models\Companies {#1336 ▼
#guarded: []
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:7 [▼
"name" => "someName"
"address_one" => "someAddress"
"address_two" => "sadaww"
"zip" => "12345"
"city" => "Berlin"
"state" => "berlin"
"country" => "Germany"
]
#original: []
#changes: []
#casts: []
#classCastCache: []
#attributeCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}
Please or to participate in this conversation.