You've already forked Atomcms-edit
Initial commit
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PreferencesController extends Controller
|
||||
{
|
||||
public function edit(): View
|
||||
{
|
||||
$user = Auth::user();
|
||||
$preferences = $user->preferences ?? $this->getDefaultPreferences();
|
||||
|
||||
return view('user.settings.preferences', [
|
||||
'preferences' => $preferences,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$validated = $request->validate([
|
||||
'radio_auto_play' => 'sometimes|boolean',
|
||||
'radio_shouts' => 'sometimes|boolean',
|
||||
'radio_notifications' => 'sometimes|boolean',
|
||||
'friend_requests' => 'sometimes|boolean',
|
||||
'room_invites' => 'sometimes|boolean',
|
||||
'email_notifications' => 'sometimes|boolean',
|
||||
]);
|
||||
|
||||
$preferences = array_merge($this->getDefaultPreferences(), $validated);
|
||||
$user->preferences = $preferences;
|
||||
$user->save();
|
||||
|
||||
return redirect()->route('settings.preferences.show')->with('success', __('Preferences updated successfully'));
|
||||
}
|
||||
|
||||
private function getDefaultPreferences(): array
|
||||
{
|
||||
return [
|
||||
'radio_auto_play' => false,
|
||||
'radio_shouts' => true,
|
||||
'radio_notifications' => true,
|
||||
'friend_requests' => true,
|
||||
'room_invites' => true,
|
||||
'email_notifications' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user