EDIT
This problem has been resolved, but I do not understand why the answer worked.
I would like to know why this did not work. Is there anyone who could explain to me?
Original question
I'm stuck in my setup, my problem is that in the settings form you can enter some email settings, but you can also change your password.
The email settings and reset password work, and my form fills it with the current userโs own data. But , when form validation fails, it redirects me back to the form without form data.
I'm not sure if I am clear, but this code below will explain this.
ChangeUserSettingRequest.php
class ChangeUserSettingsRequest extends Request { public function authorize() { if (\Auth::check()) { return true; } return false; } public function rules() { return [ 'current_password' => 'sometimes|required_with:password', 'password' => 'required_with:current_password|min:8|confirmed', 'password_confirmation' => 'required_with:password', ]; } }
settings.blade.php
{!! Form::model($settings, array('url' => route('store.settings'), 'class' => 'col s12')) !!} <p>@lang('forms.info.settings')</p> <div class="input-field col s12 m6 l6"> {!! Form::checkbox('info_mail', 0, false, ['id' => 'info_mail']) !!} {!! Form::label('info_mail', Lang::get('forms.newsletter'), ['for' => 'info_mail']) !!} </div> <div class="input-field col s12 m6 l6"> {!! Form::checkbox('message_notification', 0, false, ['id' => 'message_notification']) !!} {!! Form::label('message_notification', Lang::get('forms.messages'), ['for' => 'message_notification']) !!} </div> <div class="input-field col s12 m6 l6"> {!! Form::checkbox('friend_notification', 0, false, ['id' => 'friend_notification']) !!} {!! Form::label('friend_notification', Lang::get('forms.friendrequest'), ['for' => 'friend_notification']) !!} </div> <div class="input-field col s12 m6 l6"> {!! Form::checkbox('item_notification', 0, false, ['id' => 'item_notification']) !!} {!! Form::label('item_notification', Lang::get('forms.reactiononitem'), ['for' => 'item_notification']) !!} </div> @if ($settings and $settings->google_maps !== null) <div class="settings-explain"> <p class="margin-top-20">@lang('forms.info.companysettings')</p> </div> <div class="input-field col s12 m6 l6"> {!! Form::checkbox('type', 0, false, ['id' => 'type']) !!} {!! Form::label('type', Lang::get('forms.companytype'), ['for' => 'type']) !!} </div> <div class="input-field col s12 m6 l6"> {!! Form::checkbox('google_maps', 0, false, ['id' => 'google_maps']) !!} {!! Form::label('google_maps', Lang::get('forms.companymap'), ['for' => 'google_maps']) !!} </div> @endif <div class="settings-explain"> <p class="margin-top-20">@lang('forms.info.changepassword')</p> </div> <div class="input-field col s12"> {!! Form::label('current_password', $errors->has('current_password') ? $errors->first('current_password') : Lang::get('forms.currentpassword'), ['for' => 'current_password']) !!} {!! Form::password('current_password', ['class' => $errors->has('current_password') ? 'invalid' : '']) !!} </div> <div class="input-field col s12"> {!! Form::label('password', $errors->has('password') ? $errors->first('password') : Lang::get('forms.newpassword'), ['for' => 'password']) !!} {!! Form::password('password', ['class' => $errors->has('password') ? 'invalid' : '']) !!} </div> <div class="input-field col s12"> {!! Form::label('password_confirmation', $errors->has('password_confirmation') ? $errors->first('password_confirmation') : Lang::get('forms.repeatpassword'), ['for' => 'password_confirmation']) !!} {!! Form::password('password_confirmation', ['class' => $errors->has('password_confirmation') ? 'invalid' : '']) !!} </div> <div class="input-field col s12"> {!! Form::button(Lang::get('forms.save'), ['class' => 'btn waves-effect waves-light', 'type' => 'submit', 'name' => 'Save']) !!} </div> {!! Form::close() !!}
UserInfoController.php
public function showSettings() { $title = Lang::get('titles.settings'); $user_id = Auth::User()->id; $settings = $this->settings->getUserSettings($user_id); $companySettings = $this->companySettings->getSettings($user_id); if ($companySettings) { $settings->type = $companySettings->type; $settings->google_maps = $companySettings->google_maps; } return view('pages.users.settings', ['title' => $title])->with(compact('settings')); } public function storeSettings(ChangeUserSettingsRequest $request) { $id = Auth::User()->id; $success = $this->settings->handleStoreSettingsRequest($request);
Request.php
use Illuminate\Foundation\Http\FormRequest; abstract class Request extends FormRequest {
So my problem is that in my UserInfoController I redirect back and has good data, but when my ChangeUserSettingsRequest redirects me, the form is empty.
Does anyone know why ChangeUserSettingsRequest is not sending data?
- I'm not talking about password details, but about email settings.
- I do not want to do a costum validator, as I think it should be possible.
Please note: upon completion of verification, the storeSettings function storeSettings not be executed at all