Skip to content

Commit

Permalink
Merge pull request #31 from mr-atho/avatar
Browse files Browse the repository at this point in the history
Feat: Profile (Upload avatar), Validation Notice
  • Loading branch information
mr-atho authored Dec 20, 2022
2 parents f5e3f09 + b86623f commit 1d65a76
Show file tree
Hide file tree
Showing 54 changed files with 31,827 additions and 89 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Anda tertarik membantu dengan berkontribusi dalam mengembangkan sistem ini? Jang
- Modul Artikel

## Version
v1.5.5 | 20 Desember 2022
- Refactor: Profile (Upload avatar)
- Refactor: Validation Notice
- Fix: Bugs

v1.5.4 | 12 Desember 2022
- Refactor: Favicon

Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected function create(array $data)
'name' => $data['nama'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'avatar' => 'avatar-default.jpg',
]);
}
}
33 changes: 30 additions & 3 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Http\Controllers;

use App\Models\User;
use App\Models\ProfileModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;
use App\Models\ProfileModel;
use App\Models\User;
use Intervention\Image\Facades\Image;

class ProfileController extends Controller
{
Expand Down Expand Up @@ -66,4 +67,30 @@ public function password_change(Request $request)

return redirect()->route('login')->with('pesan', 'Password berhasil diubah. Silakan masuk kembali.');
}

public function update_avatar(Request $request)
{
if ($request->hasFile('avatar')) {

// Only allow .jpg, .bmp and .png file types.
$request->validate([
'avatar' => 'mimes:jpg,jpeg,bmp,png'
]);

$file = $request->file('avatar');
$filename = 'avatar-' . Auth::id() . '.' . $file->extension();

//Image::make($file)->resize(150, 150)->save(public_path('upload/avatars/' . $filename));
//$thumbnailpath = public_path('upload/avatars/' . $filename);
Image::make($file)->resize(150, 150)->save(public_path('upload/avatars/' . $filename));

//$request->avatar->storeAs('avatars', $name, 'public');

$user = User::find(Auth::id());
$user->avatar = $filename;
$user->save();
}

return redirect()->route('profile')->with('pesan', 'Avatar berhasil diperbaharui.');
}
}
1 change: 1 addition & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class User extends Authenticatable implements MustVerifyEmail
'name',
'email',
'password',
'avatar',
];

/**
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.0.2",
"guzzlehttp/guzzle": "^7.2",
"intervention/image": "^2.7",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
"laravel/tinker": "^2.7",
Expand Down
86 changes: 85 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
/*
* Package Service Providers...
*/
Intervention\Image\ImageServiceProvider::class,

/*
* Application Service Providers...
Expand All @@ -210,6 +211,7 @@

'aliases' => Facade::defaultAliases()->merge([
// 'ExampleClass' => App\Example\ExampleClass::class,
'Image' => Intervention\Image\Facades\Image::class,
])->toArray(),

];
20 changes: 20 additions & 0 deletions config/image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Image Driver
|--------------------------------------------------------------------------
|
| Intervention Image supports "GD Library" and "Imagick" to process images
| internally. You may choose one of them according to your PHP
| configuration. By default PHP's "GD Library" implementation is used.
|
| Supported: "gd", "imagick"
|
*/

'driver' => 'gd'

];
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('avatar')->default('avatar-default.jpg');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('avatar');
});
}
};
Loading

0 comments on commit 1d65a76

Please sign in to comment.