Update settings to have separate pages
MODIFY
app/Http/Controllers/SettingsController.php
app/Http/Controllers/SettingsController.php
@@ -13,25 +13,23 @@ use Hash;
use Mail;
class SettingsController extends Controller {
- public function index() {
- return view('settings', [
- 'languages' => config('app.locales'),
- 'currencies' => Currency::all(),
- ]);
+ public function getIndex() {
+ return redirect()->route('settings.profile');
}
- public function store(Request $request) {
+ public function postIndex(Request $request) {
$request->validate([
'avatar' => 'nullable|mimes:jpeg,jpg,png,gif',
'password' => 'nullable|confirmed',
- 'language' => 'required|in:' . implode(',', array_keys(config('app.locales'))),
- 'theme' => 'required|in:light,dark',
- 'weekly_report' => 'required|in:true,false',
- 'currency' => 'required|exists:currencies,id'
+ 'language' => 'nullable|in:' . implode(',', array_keys(config('app.locales'))),
+ 'theme' => 'nullable|in:light,dark',
+ 'weekly_report' => 'nullable|in:true,false',
+ 'currency' => 'nullable|exists:currencies,id'
]);
$user = Auth::user();
+ // Profile
if ($request->hasFile('avatar')) {
$file = $request->file('avatar');
@@ -45,25 +43,58 @@ class SettingsController extends Controller {
$user->avatar = $fileName;
}
+ if ($request->has('name')) {
$user->name = $request->input('name');
+ }
+
+ // Account
+ if ($request->has('email')) {
$user->email = $request->input('email');
- $user->currency_id = $request->input('currency');
+ }
if ($password = $request->input('password')) {
$user->password = Hash::make($password);
}
+ // Preferences
+ if ($request->has('language')) {
$user->language = $request->input('language');
+ }
+
+ if ($request->has('theme')) {
$user->theme = $request->input('theme');
+ }
+
+ if ($request->has('currency')) {
+ $user->currency_id = $request->input('currency');
+ }
+
+ if ($request->has('weekly_report')) {
$user->weekly_report = $request->input('weekly_report') == 'true' ? true : false;
+ }
$user->save();
- // If password changed
- if ($request->input('password')) {
+ // Notify upon changing of password
+ if ($request->has('password')) {
Mail::to($user->email)->queue(new PasswordChanged($user->updated_at));
}
- return redirect()->route('settings');
+ return back();
+ }
+
+ public function getProfile() {
+ return view('settings.profile');
+ }
+
+ public function getAccount() {
+ return view('settings.account');
+ }
+
+ public function getPreferences() {
+ return view('settings.preferences', [
+ 'languages' => config('app.locales'),
+ 'currencies' => Currency::all()
+ ]);
}
}

DELETE
resources/views/settings.blade.php
-@extends('layout')
-
-@section('title', __('pages.settings'))
-
-@section('body')
- <div class="wrapper my-3">
- <h2>{{ __('pages.settings') }}</h2>
- <div class="box mt-3">
- <form method="POST" enctype="multipart/form-data">
- {{ csrf_field() }}
- <div class="box__section row">
- <div class="row__column">{{ __('general.profile') }}</div>
- <div class="row__column" style="flex: 2;">
- <div class="input input--small">
- <label>{{ __('fields.avatar') }}</label>
- <img src="{{ Auth::user()->avatar }}" style="width: 200px; height: 200px; border-radius: 5px; object-fit: cover;" />
- <input type="file" name="avatar" />
- @include('partials.validation_error', ['payload' => 'avatar'])
- </div>
- <div class="input input--small">
- <label>@lang('fields.name')</label>
- <input type="text" name="name" value="{{ Auth::user()->name }}" />
- </div>
- </div>
- </div>
- <div class="box__section row">
- <div class="row__column">{{ __('general.account') }}</div>
- <div class="row__column" style="flex: 2;">
- <div class="input input--small">
- <label>{{ __('fields.email') }}</label>
- <input type="text" name="email" value="{{ Auth::user()->email }}" />
- </div>
- <div class="row">
- <div class="row__column input">
- <label>{{ __('fields.password') }}</label>
- <input type="password" name="password" />
- @include('partials.validation_error', ['payload' => 'password'])
- </div>
- <div class="row__column input ml-2">
- <label>{{ __('actions.verify') }} {{ __('fields.password') }}</label>
- <input type="password" name="password_confirmation" />
- @include('partials.validation_error', ['payload' => 'password_confirmation'])
- </div>
- </div>
- </div>
- </div>
- <div class="box__section row">
- <div class="row__column">{{ __('general.preferences') }}</div>
- <div class="row__column" style="flex: 2;">
- <div class="input input--small">
- <label>{{ __('fields.language') }}</label>
- <select name="language">
- @foreach ($languages as $key => $value)
- <option value="{{ $key }}" @if (Auth::user()->language === $key) selected @endif>{{ $value }}</option>
- @endforeach
- </select>
- @include('partials.validation_error', ['payload' => 'language'])
- </div>
- <div class="input input--small">
- <label>{{ __('fields.theme') }}</label>
- <select name="theme">
- <option value="light" {{ Auth::user()->theme == 'light' ? 'selected' : '' }}>Light</option>
- <option value="dark" {{ Auth::user()->theme == 'dark' ? 'selected' : '' }}>Dark (Experimental)</option>
- </select>
- @include('partials.validation_error', ['payload' => 'theme'])
- </div>
- <div class="input input--small">
- <label>{{ __('fields.currency') }}</label>
- <select name="currency">
- @foreach ($currencies as $currency)
- <option value="{{ $currency->id }}" {{ Auth::user()->currency_id == $currency->id ? 'selected' : '' }}>{!! $currency->symbol !!} &middot; {{ $currency->name }}</option>
- @endforeach
- </select>
- @include('partials.validation_error', ['payload' => 'currency'])
- </div>
- <div class="input input--small mb-0">
- <label>{{ __('fields.weekly_report') }}</label>
- <div>
- <input type="radio" name="weekly_report" value="true" {{ Auth::user()->weekly_report ? 'checked' : '' }} /> {{ __('actions.yes') }}
- </div>
- <div>
- <input type="radio" name="weekly_report" value="false" {{ Auth::user()->weekly_report ? '' : 'checked' }} /> {{ __('actions.no') }}
- </div>
- @include('partials.validation_error', ['payload' => 'weekly_report'])
- </div>
- </div>
- </div>
- <div class="box__section box__section--highlight text-right">
- <button class="button">{{ __('actions.save') }}</button>
- </div>
- </form>
- </div>
- </div>
-@endsection

ADD
resources/views/settings/account.blade.php
+@extends('settings.layout')
+
+@section('settings_body')
+ <div class="box">
+ <div class="box__section">
+ <div class="input input--small">
+ <label>{{ __('fields.email') }}</label>
+ <input type="text" name="email" value="{{ Auth::user()->email }}" />
+ </div>
+ <div class="row">
+ <div class="row__column input">
+ <label>{{ __('fields.password') }}</label>
+ <input type="password" name="password" />
+ @include('partials.validation_error', ['payload' => 'password'])
+ </div>
+ <div class="row__column input ml-2">
+ <label>{{ __('actions.verify') }} {{ __('fields.password') }}</label>
+ <input type="password" name="password_confirmation" />
+ @include('partials.validation_error', ['payload' => 'password_confirmation'])
+ </div>
+ </div>
+ <button class="button">{{ __('actions.save') }}</button>
+ </div>
+ </div>
+@endsection

ADD
resources/views/settings/layout.blade.php
+@extends('layout')
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2 class="mb-3">{{ __('pages.settings') }}</h2>
+ <div class="row">
+ <div class="row__column mr-3" style="max-width: 300px;">
+ <div class="box">
+ <ul class="box__section">
+ <li><a href="/settings/profile">{{ __('general.profile') }}</a></li>
+ <li><a href="/settings/account">{{ __('general.account') }}</a></li>
+ <li><a href="/settings/preferences">{{ __('general.preferences') }}</a></li>
+ </ul>
+ </div>
+ </div>
+ <div class="row__column">
+ <form method="POST" action="/settings" enctype="multipart/form-data">
+ {{ csrf_field() }}
+ @yield('settings_body')
+ </form>
+ </div>
+ </div>
+ </div>
+@endsection

ADD
resources/views/settings/preferences.blade.php
+@extends('settings.layout')
+
+@section('settings_body')
+ <div class="box">
+ <div class="box__section">
+ <div class="input input--small">
+ <label>{{ __('fields.language') }}</label>
+ <select name="language">
+ @foreach ($languages as $key => $value)
+ <option value="{{ $key }}" @if (Auth::user()->language === $key) selected @endif>{{ $value }}</option>
+ @endforeach
+ </select>
+ @include('partials.validation_error', ['payload' => 'language'])
+ </div>
+ <div class="input input--small">
+ <label>{{ __('fields.theme') }}</label>
+ <select name="theme">
+ <option value="light" {{ Auth::user()->theme == 'light' ? 'selected' : '' }}>Light</option>
+ <option value="dark" {{ Auth::user()->theme == 'dark' ? 'selected' : '' }}>Dark (Experimental)</option>
+ </select>
+ @include('partials.validation_error', ['payload' => 'theme'])
+ </div>
+ <div class="input input--small">
+ <label>{{ __('fields.currency') }}</label>
+ <select name="currency">
+ @foreach ($currencies as $currency)
+ <option value="{{ $currency->id }}" {{ Auth::user()->currency_id == $currency->id ? 'selected' : '' }}>{!! $currency->symbol !!} &middot; {{ $currency->name }}</option>
+ @endforeach
+ </select>
+ @include('partials.validation_error', ['payload' => 'currency'])
+ </div>
+ <div class="input input--small">
+ <label>{{ __('fields.weekly_report') }}</label>
+ <div>
+ <input type="radio" name="weekly_report" value="true" {{ Auth::user()->weekly_report ? 'checked' : '' }} /> {{ __('actions.yes') }}
+ </div>
+ <div>
+ <input type="radio" name="weekly_report" value="false" {{ Auth::user()->weekly_report ? '' : 'checked' }} /> {{ __('actions.no') }}
+ </div>
+ @include('partials.validation_error', ['payload' => 'weekly_report'])
+ </div>
+ <button class="button">{{ __('actions.save') }}</button>
+ </div>
+ </div>
+@endsection

ADD
resources/views/settings/profile.blade.php
+@extends('settings.layout')
+
+@section('settings_body')
+ <div class="box">
+ <div class="box__section">
+ <div class="input input--small">
+ <label>{{ __('fields.avatar') }}</label>
+ <img src="{{ Auth::user()->avatar }}" style="width: 200px; height: 200px; border-radius: 5px; object-fit: cover;" />
+ <input type="file" name="avatar" />
+ @include('partials.validation_error', ['payload' => 'avatar'])
+ </div>
+ <div class="input input--small">
+ <label>@lang('fields.name')</label>
+ <input type="text" name="name" value="{{ Auth::user()->name }}" />
+ </div>
+ <button class="button">{{ __('actions.save') }}</button>
+ </div>
+ </div>
+@endsection

MODIFY
routes/web.php
routes/web.php
@@ -64,8 +64,13 @@ Route::group(['middleware' => ['auth']], function () {
Route::delete('/imports/{import}', 'ImportController@destroy');
});
- Route::get('/settings', 'SettingsController@index')->name('settings');
- Route::post('/settings', 'SettingsController@store');
+ Route::name('settings.')->group(function () {
+ Route::get('/settings', 'SettingsController@getIndex')->name('index');
+ Route::post('/settings', 'SettingsController@postIndex');
+ Route::get('/settings/profile', 'SettingsController@getProfile')->name('profile');
+ Route::get('/settings/account', 'SettingsController@getAccount')->name('account');
+ Route::get('/settings/preferences', 'SettingsController@getPreferences')->name('preferences');
+ });
Route::get('/spaces/{id}', 'SpaceController');

Update settings to have separate pages