fixed uploaded attachment not removed

This commit is contained in:
Asif Takavala
2022-02-15 06:10:04 +00:00
committed by Mohit Panjwani
parent f34dac9d3f
commit 8ba84f68c7
9 changed files with 59 additions and 20 deletions

View File

@ -126,14 +126,14 @@ class Expense extends Model implements HasMedia
{
foreach (explode(' ', $search) as $term) {
$query->whereHas('category', function ($query) use ($term) {
$query->where('name', 'LIKE', '%'.$term.'%');
$query->where('name', 'LIKE', '%' . $term . '%');
});
}
}
public function scopeWhereNotes($query, $search)
{
$query->where('notes', 'LIKE', '%'.$search.'%');
$query->where('notes', 'LIKE', '%' . $search . '%');
}
public function scopeWhereCategory($query, $categoryId)
@ -188,9 +188,9 @@ class Expense extends Model implements HasMedia
{
foreach (explode(' ', $search) as $term) {
$query->whereHas('category', function ($query) use ($term) {
$query->where('name', 'LIKE', '%'.$term.'%');
$query->where('name', 'LIKE', '%' . $term . '%');
})
->orWhere('notes', 'LIKE', '%'.$term.'%');
->orWhere('notes', 'LIKE', '%' . $term . '%');
}
}
@ -262,6 +262,9 @@ class Expense extends Model implements HasMedia
ExchangeRateLog::addExchangeRateLog($this);
}
if (isset($request->is_attachment_receipt_removed) && (bool) $request->is_attachment_receipt_removed) {
$this->clearMediaCollection('receipts');
}
if ($request->hasFile('attachment_receipt')) {
$this->clearMediaCollection('receipts');
$this->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts');