diff --git a/.travis.yml b/.travis.yml index 6fd0b19..feb0c88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ before_script: - travis_retry composer install --prefer-source --no-interaction --dev - cp .env.example .env - php artisan key:generate + - php artisan storage:link script: - vendor/bin/phpunit diff --git a/app/Helpers/functions.php b/app/Helpers/functions.php index 5986646..9ae2148 100644 --- a/app/Helpers/functions.php +++ b/app/Helpers/functions.php @@ -1,31 +1,40 @@ = 1073741824) - { - $bytes = number_format($bytes / 1073741824, 2) . ' GB'; - } - elseif ($bytes >= 1048576) - { - $bytes = number_format($bytes / 1048576, 2) . ' MB'; - } - elseif ($bytes >= 1024) - { - $bytes = number_format($bytes / 1024, 2) . ' KB'; - } - elseif ($bytes > 1) - { - $bytes = $bytes . ' bytes'; - } - elseif ($bytes == 1) - { - $bytes = $bytes . ' byte'; - } - else - { + if ($bytes >= 1073741824) { + $bytes = number_format($bytes / 1073741824, 2).' GB'; + } elseif ($bytes >= 1048576) { + $bytes = number_format($bytes / 1048576, 2).' MB'; + } elseif ($bytes >= 1024) { + $bytes = number_format($bytes / 1024, 2).' KB'; + } elseif ($bytes > 1) { + $bytes = $bytes.' bytes'; + } elseif ($bytes == 1) { + $bytes = $bytes.' byte'; + } else { $bytes = '0 bytes'; } return $bytes; -} \ No newline at end of file +} + +function userPhoto(User $user, $attributes = []) +{ + return Html::image( + userPhotoPath($user->photo_path, $user->gender_id), + null, + $attributes + ); +} + +function userPhotoPath($photoPath, $genderId) +{ + if (is_file(public_path('foto_profile/'.$photoPath))) { + return asset('foto_profile/'.$photoPath); + } + + return asset('images/icon_user_'.$genderId.'.png'); +} diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 2412b20..06eaace 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -119,18 +119,19 @@ class UsersController extends Controller public function update(Request $request, User $user) { $this->validate($request, [ - 'nickname' => 'required|string|max:255', - 'name' => 'required|string|max:255', - 'gender_id' => 'required|numeric', - 'dob' => 'nullable|date|date_format:Y-m-d', - 'dod' => 'nullable|date|date_format:Y-m-d', - 'yod' => 'nullable|date_format:Y', - 'phone' => 'nullable|string|max:255', - 'job' => 'nullable|string|max:255', - 'address' => 'nullable|string|max:255', - 'city' => 'nullable|string|max:255', - 'email' => 'nullable|string|max:255', - 'password' => 'nullable|min:6|max:15', + 'nickname' => 'required|string|max:255', + 'name' => 'required|string|max:255', + 'gender_id' => 'required|numeric', + 'dob' => 'nullable|date|date_format:Y-m-d', + 'dod' => 'nullable|date|date_format:Y-m-d', + 'yod' => 'nullable|date_format:Y', + 'phone' => 'nullable|string|max:255', + 'job' => 'nullable|string|max:255', + 'job_description' => 'nullable|string|max:255', + 'address' => 'nullable|string|max:255', + 'city' => 'nullable|string|max:255', + 'email' => 'nullable|string|max:255', + // 'password' => 'nullable|min:6|max:15', ]); $user->nickname = $request->nickname; @@ -145,15 +146,16 @@ class UsersController extends Controller $user->yod = $request->get('yod'); } - $user->phone = $request->get('phone'); - $user->job = $request->get('job'); - $user->address = $request->get('address'); - $user->city = $request->get('city'); - $user->email = $request->get('email'); + $user->phone = $request->get('phone'); + $user->job = $request->get('job'); + $user->job_description = $request->get('job_description'); + $user->address = $request->get('address'); + $user->city = $request->get('city'); + $user->email = $request->get('email'); - if ($request->get('email')) { - $user->password = bcrypt($request->get('email')); - } + // if ($request->get('email')) { + // $user->password = bcrypt($request->get('email')); + // } $user->save(); @@ -166,10 +168,26 @@ class UsersController extends Controller * @param \App\User $user * @return \Illuminate\Http\Response */ + // public function destroy(User $user) + // { + // // + // } + public function destroy(User $user) { - $user->delete('manager_id'); - return redirect()->route('users.search'); + $this->authorize('delete', $user); + + $this->validate(request(), [ + 'user' => 'required', + ]); + + $routeParam = request()->only('page', 'q'); + + if (request('user') == $user->id && $user->delete()) { + return redirect()->route('users.profile', $routeParam); + } + + return back(); } /** @@ -183,7 +201,7 @@ class UsersController extends Controller public function photoUpload(Request $request, User $user) { $request->validate([ - 'photo' => 'required|image|max:200', + 'photo' => 'required|image|max:2000', ]); $storage = env('APP_ENV') == 'testing' ? 'avatars' : 'public'; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 28a1b53..3a88480 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -28,8 +28,6 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - if ($this->app->environment() == 'local') { - $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class); - } + // } } diff --git a/config/database.php b/config/database.php index 5ed066d..f8c3a85 100644 --- a/config/database.php +++ b/config/database.php @@ -45,7 +45,7 @@ return [ 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), - 'password' => env('DB_PASSWORD', ''), + 'password' => env('DB_PASSWORD', 'secret'), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', diff --git a/config/filesystems.php b/config/filesystems.php index 4544f60..e0b5034 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -45,12 +45,12 @@ return [ 'local' => [ 'driver' => 'local', - 'root' => storage_path('app'), + 'root' => public_path('foto_profile'), ], 'public' => [ 'driver' => 'local', - 'root' => storage_path('app/public'), + 'root' => public_path('foto_profile'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', ], diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index b5b0155..12c0b92 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -30,6 +30,7 @@ class CreateUsersTable extends Migration $table->string('city')->nullable(); $table->string('phone')->nullable(); $table->string('job')->nullable(); + $table->string('job_description')->nullable(); $table->string('photo_path')->nullable(); $table->uuid('manager_id')->nullable(); $table->rememberToken(); diff --git a/public/app/public/foto_profile/foto_profile/j79aI14c23A4daF1YEOXLH3lqoWWWghdVri4PXuY.jpeg b/public/app/public/foto_profile/foto_profile/j79aI14c23A4daF1YEOXLH3lqoWWWghdVri4PXuY.jpeg new file mode 100644 index 0000000..e6e4ca6 Binary files /dev/null and b/public/app/public/foto_profile/foto_profile/j79aI14c23A4daF1YEOXLH3lqoWWWghdVri4PXuY.jpeg differ diff --git a/public/foto_profile/images/rzy1dxWSFLXiPO68KdUEvEMLfKBxOk711Bd7tEVt.jpeg b/public/foto_profile/images/rzy1dxWSFLXiPO68KdUEvEMLfKBxOk711Bd7tEVt.jpeg new file mode 100644 index 0000000..e6e4ca6 Binary files /dev/null and b/public/foto_profile/images/rzy1dxWSFLXiPO68KdUEvEMLfKBxOk711Bd7tEVt.jpeg differ diff --git a/resources/lang/en/app.php b/resources/lang/en/app.php index 0a3633c..54ee9a9 100644 --- a/resources/lang/en/app.php +++ b/resources/lang/en/app.php @@ -22,6 +22,7 @@ return [ 'city' => 'City', 'phone' => 'Phone', 'job' => 'Job', + 'job_description' => 'Job Description', 'login_account' => 'Login Account', 'childs_were_not_recorded' => 'Childs were not recorded.', diff --git a/resources/lang/en/user.php b/resources/lang/en/user.php index f77b85f..a9f3ac6 100644 --- a/resources/lang/en/user.php +++ b/resources/lang/en/user.php @@ -45,6 +45,7 @@ return [ 'city' => 'City', 'phone' => 'Phone', 'job' => 'Job', + 'job_description' => 'Job Description', 'manager' => 'Manager', // Photo diff --git a/resources/lang/id/app.php b/resources/lang/id/app.php index 841e93f..7157996 100644 --- a/resources/lang/id/app.php +++ b/resources/lang/id/app.php @@ -22,6 +22,7 @@ return [ 'city' => 'Kota', 'phone' => 'Telp.', 'job' => 'Pekerjaan', + 'job_description' => 'Bidang Pekerjaan', 'login_account' => 'Akun Login', 'childs_were_not_recorded' => 'Anak-anak belum tercatat.', diff --git a/resources/lang/id/user.php b/resources/lang/id/user.php index 9345d39..36f4b59 100644 --- a/resources/lang/id/user.php +++ b/resources/lang/id/user.php @@ -45,6 +45,7 @@ return [ 'city' => 'Kota', 'phone' => 'Telp.', 'job' => 'Pekerjaan', + 'job_description' => 'Bidang Pekerjaan', 'manager' => 'Pengelola', // Photo diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 0701e3f..f1551fb 100644 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -1,7 +1,44 @@ @extends('layouts.app') +@section('title', trans('user.edit')) + @section('content')
{{ Form::model($user, ['route' => ['users.update', $user->id], 'method' =>'patch', 'autocomplete' => 'off']) }} - {{ Form::model($user, ['route' => ['users.destroy', $user->id], 'method' =>'delete', 'autocomplete' => 'on']) }}

{{ trans('user.edit') }}

-
- @if ($user->photo_path && is_file(public_path('storage/'.$user->photo_path))) - {{ Html::image('storage/'.$user->photo_path, $user->name, ['style' => 'max-width:100%']) }} - @else - {{ Html::image('images/icon_user_'.$user->gender_id.'.png', $user->name, ['style' => 'max-width:100%']) }} - @endif -
{!! FormField::text('name', ['label' => trans('user.name')]) !!} {!! FormField::text('nickname', ['label' => trans('user.nickname')]) !!}
@@ -33,6 +62,13 @@
+
+

{{ trans('app.login_account') }}

+
+ {!! FormField::email('email', ['label' => trans('auth.email'), 'placeholder' => trans('app.example').' nama@mail.com']) !!} + +
+
@@ -41,29 +77,35 @@ {!! FormField::textarea('address', ['label' => trans('app.address')]) !!} {!! FormField::text('city', ['label' => trans('app.city'), 'placeholder' => trans('app.example').' Jakarta']) !!} {!! FormField::text('phone', ['label' => trans('app.phone'), 'placeholder' => trans('app.example').' 081234567890']) !!} - {!! FormField::text('job', ['label' => trans('app.job'), 'placeholder' => trans('app.example').' Karyawan']) !!} -
-
-
-

{{ trans('app.login_account') }}

-
- {!! FormField::email('email', ['label' => trans('auth.email'), 'placeholder' => trans('app.example').' nama@mail.com']) !!} - {!! FormField::text('password', ['label' => trans('auth.password'), 'placeholder' => '******', 'value' => '']) !!} + {!! FormField::text('job', ['label' => trans('user.job'), 'placeholder' => trans('app.example').' Karyawan']) !!} + {!! FormField::textarea('job_description', ['label' => trans('app.job_description')]) !!}
{{ Form::submit(trans('app.update'), ['class' => 'btn btn-primary']) }} - {{ Form::submit(trans('app.delete'), ['class' => 'btn btn-danger']) }} + {{ link_to_route('users.edit', trans('app.delete'), [$user, 'action' => 'delete'], ['class' => 'btn btn-danger pull-center', 'id' => 'del-users-'.$user->id]) }} {{ link_to_route('users.show', trans('app.cancel'), [$user->id], ['class' => 'btn btn-default']) }}
{{ Form::close() }}
- {{ Form::open(['route' => ['users.photo-upload', $user], 'method' => 'patch', 'files' => true]) }} - {!! FormField::file('photo', ['required' => true, 'label' => __('user.reupload_photo'), 'info' => ['text' => 'Format jpg, maks: 200 Kb.', 'class' => 'warning']]) !!} - {!! Form::submit(__('user.update_photo'), ['class' => 'btn btn-success']) !!} - {{ link_to_route('users.show', trans('app.cancel'), [$user], ['class' => 'btn btn-default']) }} - {{ Form::close() }} +
+

{{ __('user.update_photo') }}

+ {{ Form::open(['route' => ['users.photo-upload', $user], 'method' => 'patch', 'files' => true]) }} +
+ {{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }} +
+
+ {!! FormField::file('photo', ['required' => true, 'label' => __('user.reupload_photo'), 'info' => ['text' => 'Format jpg, maks: 2 Mb.', 'class' => 'warning']]) !!} +
+ + {{ Form::close() }} +
+@endif @endsection diff --git a/resources/views/users/partials/profile.blade.php b/resources/views/users/partials/profile.blade.php index 462fa20..21807fc 100644 --- a/resources/views/users/partials/profile.blade.php +++ b/resources/views/users/partials/profile.blade.php @@ -1,11 +1,7 @@

{{ trans('user.profile') }}

- @if ($user->photo_path && is_file(public_path('storage/'.$user->photo_path))) - {{ Html::image('storage/'.$user->photo_path, $user->name, ['style' => 'max-width:100%']) }} - @else - {{ Html::image('images/icon_user_'.$user->gender_id.'.png', $user->name, ['style' => 'max-width:100%']) }} - @endif + {{ userPhoto($user, ['style' => 'width:100%;max-width:300px']) }}
@@ -40,6 +36,14 @@ @endif + + + + + + + + diff --git a/resources/views/users/search.blade.php b/resources/views/users/search.blade.php index 5830207..a08dbb4 100644 --- a/resources/views/users/search.blade.php +++ b/resources/views/users/search.blade.php @@ -1,5 +1,6 @@ @extends('layouts.app') +@section('user-content') @section('content')
{{ trans('user.job') }}{{ $user->job }}
{{ trans('user.job_description') }}{{ $user->job_description }}
{{ trans('user.phone') }} {{ $user->phone }}