Attachment file update

This commit is contained in:
cuneytsenturk 2017-12-29 19:56:56 +03:00
parent 94b7e9ec64
commit 3e04f1295b
7 changed files with 66 additions and 5 deletions

View File

@ -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.
*

View File

@ -0,0 +1,14 @@
<?php
namespace App\Models\Common;
use Illuminate\Database\Eloquent\SoftDeletes;
use Plank\Mediable\Media as PMedia;
class Media extends PMedia
{
use SoftDeletes;
protected $dates = ['deleted_at'];
}

View File

@ -150,6 +150,6 @@ class Invoice extends Model
return false;
}
return $this->getMedia('attachment')->first();
return $this->getMedia('attachment')->last();
}
}

View File

@ -224,5 +224,5 @@ return [
/**
* Detach associated media when mediable model is soft deleted.
*/
'detach_on_soft_delete' => true,
'detach_on_soft_delete' => false,
];

View File

@ -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']);

View File

@ -180,8 +180,23 @@
</div>
@if($invoice->attachment)
<span>
<a href=""><i class="fa fa-file-{{ $invoice->attachment->aggregate_type }}-o"></i> {{ $invoice->attachment->basename }}</a> <i class="fa fa fa-times"></i>
<span class="attachment">
<a href="{{ url('uploads/invoices/' . $invoice->attachment->basename . '/download') }}">
<span id="download-attachment" class="text-primary">
<i class="fa fa-file-{{ $invoice->attachment->aggregate_type }}-o"></i> {{ $invoice->attachment->basename }}
</span>
</a>
{!! Form::open([
'id' => 'attachment-' . $invoice->attachment->id,
'method' => 'DELETE',
'url' => [url('uploads/invoices/' . $invoice->attachment->id)],
'style' => 'display:inline'
]) !!}
{{ Form::hidden('id', $invoice->id) }}
<a id="remove-attachment" href="javascript:void();">
<span class="text-danger"><i class="fa fa fa-times"></i></span>
</a>
{!! Form::close() !!}
</span>
@endif
</div>
@ -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' => '<strong>' . $invoice->attachment->basename . '</strong>', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}");
});
@endif
});
function addPayment() {

View File

@ -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 () {