@@ -45,12 +45,14 @@ class PageController extends Controller
|
||||
}
|
||||
}, Storage::disk('pages')->files(Auth::user()->getAuthIdentifier())));
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
return view('pages.index', [
|
||||
'start_date'=> min((new DateTime())->sub(new DateInterval('P1Y')), $user->created_at),
|
||||
'checkword' => $user->checkword,
|
||||
'pages' => $pages,
|
||||
'start_date' => min((new DateTime())->sub(new DateInterval('P1Y')), $user->created_at),
|
||||
'checkword' => $user->checkword,
|
||||
'settings' => json_encode($user->getSettings()),
|
||||
'pages' => $pages,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -124,7 +126,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
throw new MethodNotAllowedHttpException('You can\'t edit a page.');
|
||||
throw new MethodNotAllowedHttpException(['GET'], 'You can\'t edit a page.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +139,7 @@ class PageController extends Controller
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
throw new MethodNotAllowedHttpException('You can\'t edit a page.');
|
||||
throw new MethodNotAllowedHttpException(['GET'], 'You can\'t edit a page.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\User\SettingsRequest;
|
||||
use App\Http\Requests\User\WordCheckRequest;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -23,4 +24,26 @@ class UserController extends Controller
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function settings()
|
||||
{
|
||||
return view('user.settings', [
|
||||
'settings' => Auth::user()->getSettings(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function storeSettings(SettingsRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
$user = User::where('id', Auth::user()->getAuthIdentifier())->firstOrFail();
|
||||
foreach ($validated as $name => $value) {
|
||||
$user->{$name} = $value;
|
||||
}
|
||||
$user->save();
|
||||
Auth::setUser($user);
|
||||
|
||||
$request->session()->flash('status', __('Settings saved!'));
|
||||
|
||||
return redirect()->route('user.settings');
|
||||
}
|
||||
}
|
||||
|
34
app/Http/Requests/User/SettingsRequest.php
Normal file
34
app/Http/Requests/User/SettingsRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\User;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SettingsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'text_color' => ['required', 'string', 'max:7'],
|
||||
'background_color' => ['required', 'string', 'max:7'],
|
||||
'font' => ['required', 'string', 'max:255'],
|
||||
'font_size' => ['required', 'numeric'],
|
||||
'line_spacing' => ['required', 'numeric'],
|
||||
];
|
||||
}
|
||||
}
|
@@ -33,6 +33,14 @@ class User extends Authenticatable
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $settings = [
|
||||
'text_color',
|
||||
'background_color',
|
||||
'font',
|
||||
'font_size',
|
||||
'line_spacing',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
@@ -41,4 +49,17 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings()
|
||||
{
|
||||
$settings = [];
|
||||
foreach ($this->settings as $setting) {
|
||||
$settings[$setting] = $this->{$setting};
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user