added avatar to user

pull/49/head
A1Gard 2 months ago
parent 388a22f9cb
commit a45724c163

@ -9,6 +9,7 @@ use App\Models\Access;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Helper; use App\Helper;
use Spatie\Image\Image;
use function App\Helpers\hasCreateRoute; use function App\Helpers\hasCreateRoute;
class UserController extends XController class UserController extends XController
@ -34,6 +35,7 @@ class UserController extends XController
public function save($user, $request) public function save($user, $request)
{ {
// dd($request->all());
if ($user->role == 'DEVELOPER' && !auth()->user()->hasRole('developer')) { if ($user->role == 'DEVELOPER' && !auth()->user()->hasRole('developer')) {
abort(403); abort(403);
} }
@ -70,6 +72,25 @@ class UserController extends XController
} }
} }
if ($request->hasFile('avatar')) {
$name = time() . '.' . request()->avatar->getClientOriginalExtension();
$user->avatar = $name;
$request->file('avatar')->storeAs('public/users', $name);
$format = $request->file('avatar')->guessExtension();
$format = 'webp';
$key = 'avatar';
$i = Image::load($request->file($key)->getPathname())
->optimize()
->width(500)
->height(500)
->crop(500, 500)
// ->nonQueued()
->format($format);
$i->save(storage_path() . '/app/public/users/'. $user->avatar);
$user->save();
}
return $user; return $user;
} }

@ -166,4 +166,14 @@ class User extends Authenticatable
->where('evaluationable_id',$this->id); ->where('evaluationable_id',$this->id);
})->get(); })->get();
} }
public function avatar(){
if ($this->avatar == null || trim($this->avatar) == ''){
return asset('assets/default/unknown.svg');
}
return \Storage::url('users/' . $this->avatar);
}
} }

@ -31,7 +31,14 @@
@endif @endif
</ul> </ul>
</div> </div>
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-user-3-line"></i>
{{__("Avatar")}}
</h3>
<img src="{{$item->avatar()}}" class="img-fluid mb-3" alt="" data-open-file="#avatar-input">
<input type="file" name="avatar" id="avatar-input" accept="image/jpeg">
</div>
</div> </div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1"> <div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form "> <div class="general-form ">

@ -9,7 +9,7 @@
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-3 text-center"> <div class="col-3 text-center">
<img src="{{asset('panel/images/xshop-logo.svg')}}" class="avatar-x64" alt=""> <img src="{{auth()->user()->avatar()}}" class="avatar-x64" alt="">
</div> </div>
<div class="col-9 pt-1"> <div class="col-9 pt-1">
{{__("Welcome back")}} {{__("Welcome back")}}

Loading…
Cancel
Save