mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-28 11:00:39 +00:00
Generate multiple avatar sizes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace App\Users\Controllers\Account;
|
||||
|
||||
use App\Users\Requests\UpdateUserProfileSettingsRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -12,26 +13,13 @@ class UpdateProfileSettingsController extends Controller
|
||||
/**
|
||||
* Update user settings
|
||||
*/
|
||||
public function __invoke(Request $request): Response
|
||||
public function __invoke(UpdateUserProfileSettingsRequest $request): Response
|
||||
{
|
||||
// Validate request
|
||||
// TODO: pridat validator do requestu
|
||||
$validator = Validator::make($request->all(), [
|
||||
'avatar' => 'sometimes|file',
|
||||
'name' => 'string',
|
||||
'value' => 'string',
|
||||
]);
|
||||
|
||||
// Return error
|
||||
if ($validator->fails()) {
|
||||
abort(400, 'Bad input');
|
||||
}
|
||||
|
||||
// Get user
|
||||
$user = Auth::user();
|
||||
|
||||
// Check if is demo
|
||||
abort_if(is_demo_account($user->email), 204, 'Done.');
|
||||
abort_if(is_demo_account(), 204, 'Done.');
|
||||
|
||||
// Update avatar
|
||||
if ($request->hasFile('avatar')) {
|
||||
|
||||
@@ -16,7 +16,7 @@ class UserSettings extends Model
|
||||
/**
|
||||
* Format avatar to full url
|
||||
*
|
||||
* @return \Illuminate\Contracts\Routing\UrlGenerator|string
|
||||
* @return \Illuminate\Contracts\Routing\UrlGenerator|string|array
|
||||
*/
|
||||
public function getAvatarAttribute()
|
||||
{
|
||||
@@ -27,7 +27,14 @@ class UserSettings extends Model
|
||||
|
||||
// Get avatar from local storage
|
||||
if ($this->attributes['avatar']) {
|
||||
return url('/' . $this->attributes['avatar']);
|
||||
|
||||
$link = [];
|
||||
|
||||
foreach (config('vuefilemanager.avatar_sizes') as $item) {
|
||||
$link[$item['name']] = url("/avatars/{$item['name']}-{$this->attributes['avatar']}");
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateUserProfileSettingsRequest 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 [
|
||||
'avatar' => 'sometimes|file',
|
||||
'name' => 'string',
|
||||
'value' => 'string',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user