diff --git a/app/Http/Controllers/ClientPortal/DocumentController.php b/app/Http/Controllers/ClientPortal/DocumentController.php
index cbb0366ff2f4..0773d5b98360 100644
--- a/app/Http/Controllers/ClientPortal/DocumentController.php
+++ b/app/Http/Controllers/ClientPortal/DocumentController.php
@@ -55,17 +55,15 @@ class DocumentController extends Controller
Storage::makeDirectory('public/' . $contact->client->client_hash, 0755);
$path = Storage::putFile('public/' . $contact->client->client_hash, $request->file('file'));
-
$url = Storage::url($path);
-
- Log::error($path);
- Log::error($url);
+ $size = $request->file('file')->getSize();
+ $type = $request->file('file')->getClientOriginalExtension();
$contact = auth()->user();
-
- tap($contact)->update([
- 'avatar' => $url,
- ]);
+ $contact->avatar_size = $size;
+ $contact->avatar_type = $type;
+ $contact->avatar = $url;
+ $contact->save();
/*
[2019-08-07 05:50:23] local.ERROR: array (
@@ -82,6 +80,9 @@ class DocumentController extends Controller
)),
)
*/
+
+ return response()->json($contact);
+
}
/**
@@ -124,8 +125,22 @@ class DocumentController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function destroy($id)
+ public function destroy()
{
- //
+ $contact = auth()->user();
+
+ $file = basename($contact->avatar);
+ $image_path = 'public/' . $contact->client->client_hash . '/' . $file;
+
+ Log::error($image_path);
+ Storage::delete($image_path);
+
+
+ $contact->avatar = '';
+ $contact->avatar_type = '';
+ $contact->avatar_size = '';
+ $contact->save();
+
+ return response()->json($contact);
}
}
diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php
index 23af7b319838..71bab7d09322 100644
--- a/app/Models/ClientContact.php
+++ b/app/Models/ClientContact.php
@@ -55,6 +55,14 @@ class ClientContact extends Authenticatable
protected $hidden = [
'password',
'remember_token',
+ 'user_id',
+ 'company_id',
+ 'client_id',
+ 'google_2fa_secret',
+ 'id',
+ 'oauth_provider_id',
+ 'oauth_user_id',
+ 'token',
];
@@ -84,7 +92,7 @@ class ClientContact extends Authenticatable
public function setAvatarAttribute($value)
{
- if(!filter_var($value, FILTER_VALIDATE_URL))
+ if(!filter_var($value, FILTER_VALIDATE_URL) && $value)
$this->attributes['avatar'] = url('/') . $value;
else
$this->attributes['avatar'] = $value;
diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php
index 3bd4a45308b3..a1844d31d2f7 100644
--- a/database/migrations/2014_10_13_000000_create_users_table.php
+++ b/database/migrations/2014_10_13_000000_create_users_table.php
@@ -329,9 +329,8 @@ class CreateUsersTable extends Migration
$table->string('google_2fa_secret')->nullable();
$table->string('accepted_terms_version')->nullable();
$table->string('avatar', 255)->nullable();
- $table->unsignedInteger('avatar_width')->nullable();
- $table->unsignedInteger('avatar_height')->nullable();
- $table->unsignedInteger('avatar_size')->nullable();
+ $table->string('avatar_type',255)->nullable();
+ $table->string('avatar_size',255)->nullable();
$table->string('password');
$table->string('token')->nullable();
$table->boolean('is_locked')->default(false);
diff --git a/resources/views/generic/dropzone.blade.php b/resources/views/generic/dropzone.blade.php
index ddeda7c5ea6f..a023bab4d356 100644
--- a/resources/views/generic/dropzone.blade.php
+++ b/resources/views/generic/dropzone.blade.php
@@ -30,6 +30,9 @@
-@endpush
\ No newline at end of file
+@endpush
diff --git a/routes/client.php b/routes/client.php
index 73ddec683cd4..68d13207ad47 100644
--- a/routes/client.php
+++ b/routes/client.php
@@ -20,6 +20,7 @@ Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'c
Route::put('profile/{client_contact}/edit', 'ClientPortal\ProfileController@update')->name('profile.update');
Route::post('document', 'ClientPortal\DocumentController@store')->name('document.store');
+ Route::delete('document', 'ClientPortal\DocumentController@destroy')->name('document.destroy');
Route::get('logout', 'Auth\ContactLoginController@logout')->name('logout');