diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index a22904bd3..0b3a975c2 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Common; use App\Http\Controllers\Controller; +use App\Models\Common\Media; use Storage; class Uploads extends Controller @@ -41,6 +42,31 @@ class Uploads extends Controller return response()->download($path); } + /** + * Destroy the specified resource. + * + * @param $folder + * @param $file + * @return callable + */ + public function destroy($folder, $id) + { + $media = Media::find($id); + + // Get file path + /*if (!$path = $this->getPath($folder, $id)) { + $message = trans('messages.warning.deleted', ['name' => $file, 'text' => $file]); + + flash($message)->warning(); + + return back(); + }*/ + + $media->delete(); //will not delete files + + return back(); + } + /** * Get the full path of resource. * diff --git a/app/Models/Common/Media.php b/app/Models/Common/Media.php new file mode 100644 index 000000000..744d67644 --- /dev/null +++ b/app/Models/Common/Media.php @@ -0,0 +1,14 @@ +getMedia('attachment')->first(); + return $this->getMedia('attachment')->last(); } } diff --git a/config/mediable.php b/config/mediable.php index e28f8dd8c..9f468220e 100644 --- a/config/mediable.php +++ b/config/mediable.php @@ -224,5 +224,5 @@ return [ /** * Detach associated media when mediable model is soft deleted. */ - 'detach_on_soft_delete' => true, + 'detach_on_soft_delete' => false, ]; diff --git a/database/migrations/2016_06_27_000000_create_mediable_tables.php b/database/migrations/2017_12_30_000000_create_mediable_tables.php similarity index 98% rename from database/migrations/2016_06_27_000000_create_mediable_tables.php rename to database/migrations/2017_12_30_000000_create_mediable_tables.php index b35c40ecd..f9dd1f1a4 100644 --- a/database/migrations/2016_06_27_000000_create_mediable_tables.php +++ b/database/migrations/2017_12_30_000000_create_mediable_tables.php @@ -23,6 +23,7 @@ class CreateMediableTables extends Migration $table->string('aggregate_type', 32); $table->integer('size')->unsigned(); $table->timestamps(); + $table->softDeletes(); $table->index(['disk', 'directory']); $table->unique(['disk', 'directory', 'filename', 'extension']); diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index 1b4cbaaa5..1e0cc2dbd 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -180,8 +180,23 @@ @if($invoice->attachment) - - {{ $invoice->attachment->basename }} + + + + {{ $invoice->attachment->basename }} + + + {!! Form::open([ + 'id' => 'attachment-' . $invoice->attachment->id, + 'method' => 'DELETE', + 'url' => [url('uploads/invoices/' . $invoice->attachment->id)], + 'style' => 'display:inline' + ]) !!} + {{ Form::hidden('id', $invoice->id) }} + + + + {!! Form::close() !!} @endif @@ -420,6 +435,11 @@ $('#email-modal').modal('show'); }); + @if($invoice->attachment) + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $invoice->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $invoice->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endif }); function addPayment() { diff --git a/routes/web.php b/routes/web.php index 91e744610..b09ee7557 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,7 +11,7 @@ Route::group(['middleware' => 'language'], function () { Route::group(['prefix' => 'uploads'], function () { Route::get('{folder}/{file}', 'Common\Uploads@get'); Route::get('{folder}/{file}/download', 'Common\Uploads@download'); - Route::get('{folder}/{file}/destroy', 'Common\Uploads@destroy'); + Route::delete('{folder}/{id}', 'Common\Uploads@destroy'); }); Route::group(['middleware' => ['adminmenu', 'permission:read-admin-panel']], function () {