Skip to content

Commit

Permalink
profile editing
Browse files Browse the repository at this point in the history
  • Loading branch information
makssein committed Aug 27, 2023
1 parent 4d4196f commit 1649c62
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 91 deletions.
33 changes: 22 additions & 11 deletions app/Http/Controllers/Web/Account/EditProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,33 @@
use App\Http\Requests\Account\EditProfileRequest;
use App\Models\ProfileInfoModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class EditProfileController extends Controller {
public function edit(EditProfileRequest $request) {
$profile_info = ProfileInfoModel::updateOrCreate(
['user_id' => auth()->user()->id],
[
'bio' => $request->post('bio'),
'link' => $request->post('link')
]
);

auth()->user()->name = $request->name;
$save = auth()->user()->save();
auth()->user()->name = $request->post('name');
auth()->user()->bio = $request->post('bio');
auth()->user()->website = $request->post('website');

if($request->hasFile('avatar')) {
auth()->user()->avatar = $request->file('avatar')->store('avatars');
}

if($request->hasFile('banner')) {
auth()->user()->banner = $request->file('banner')->store('banners');
}

if($request->has('delete_banner')) {
if(auth()->user()->banner) {
Storage::disk('public')->delete(auth()->user()->banner);
}

auth()->user()->banner = null;
}

$save = auth()->user()->save();

if($profile_info && $save) {
if($save) {
return response()->json([
'status' => true,
'type' => 'success',
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Web/Account/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function signup(SignUpRequest $request) {
$user = User::create($request->validated());

if($user) {
Auth::login($user);
$user->notify(new VerifyEmailNotification);

return response()->json([
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Web/Account/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
class ProfileController extends Controller
{
public function render(User $user) {
$profile_info = $user->profileInfo;
return view('pages/account/profile', compact('user', 'profile_info'));
return view('pages/account/profile', compact('user'));
}
}
19 changes: 14 additions & 5 deletions app/Http/Requests/Account/EditProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,34 @@ public function rules(): array {
return [
'name' => 'required|min:3|string|max:255',
'bio' => 'nullable|string|min:5|max:255',
'link' => 'nullable|active_url'
'website' => 'nullable|active_url',
'banner' => 'nullable|image|max:5120|mimes:jpg,png',
'avatar' => 'nullable|image|max:5120|mimes:jpg,png',
'delete_banner' => 'sometimes'
];
}

public function attributes() : array {
return [
'name' => 'Имя',
'bio' => 'Описание',
'link' => 'Ссылка'
'website' => 'Ссылка',
'banner' => 'Баннер',
'avatar' => 'Аватар'
];
}

public function messages() : array {
return [
'required' => ":attribute является обязательным полем.",
'min' => ':attribute должен быть минимум :min символов.',
'name.min' => ':attribute должен быть минимум :min символов.',
'string' => ':attribute должен быть строкой.',
'max' => ':attribute может быть максимум :max символов.',
'active_url' => ':attribute должна быть рабочей ссылкой.'
'name.max' => ':attribute может быть максимум :max символов.',
'active_url' => ':attribute должна быть рабочей ссылкой.',
'image' => ':attribute должен быть изображением.',
'banner.max' => ':attribute может быть максимум :max КБ',
'avatar.max' => ':attribute может быть максимум :max КБ',
'mimes' => ':attribute может быть только в формате PNG, JPG.'
];
}

Expand Down
10 changes: 8 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class User extends Authenticatable
'username',
'email',
'password',
'avatar',
'banner'
];

/**
Expand Down Expand Up @@ -61,7 +63,11 @@ public function profileLink() {
return route('profile.profile', $this->username);
}

public function profileInfo() {
return $this->hasOne(ProfileInfoModel::class);
public function getAvatarLink() {
return url('/storage/'.$this->avatar);
}

public function getBannerLink() {
return url('/storage/'.$this->banner);
}
}
16 changes: 1 addition & 15 deletions app/Traits/Followable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,8 @@ public function follows()
'user_id', 'following_user_id');
}

public function follow(User $user)
{
return $this->follows()->save($user);
}

public function unfollow(User $user)
{
return $this->follows()->detach($user);
}

public function toggleFollow(User $user) {
if($this->isFollowing($user)) {
return $this->unfollow($user);
}

return $this->follow($user);
return $this->follows()->toggle($user);
}


Expand Down
6 changes: 5 additions & 1 deletion database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public function up(): void
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('username');
$table->string('username')->unique();
$table->string('avatar')->nullable();
$table->string('banner')->nullable();
$table->string('bio')->nullable();
$table->string('website')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
Expand Down
31 changes: 0 additions & 31 deletions database/migrations/2023_08_26_213732_profile_info_migration.php

This file was deleted.

4 changes: 4 additions & 0 deletions public/img/default/default-avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1649c62

Please sign in to comment.