soft-delete

getDirty() Soft Deleted Item in deleted() Observer Method, Laravel 5.8

◇◆丶佛笑我妖孽 提交于 2020-01-25 04:01:08
问题 I want to delete an image every time I delete an item so I tried using an observer and put my code in deleted method, but I can't get deleted data although I'm using soft delete. I already try this in my observer, but it fail. public function deleted(Board $board) { $thisBoard = Board::withTrashed()->getDirty(); $imageName = $thisBoard['image']; Storage::delete("public/" . $board->getImageFolder() . $imageName); Storage::delete("public/" . $board->getImageFolder() . "thumbnail/{$imageName}");

Logical delete at a common place in hibernate

旧街凉风 提交于 2020-01-02 23:33:46
问题 I am using Spring and Hibernate for my application. I am only allowing logical delete in my application where I need to set the field isActive=false. Instead of repeating the same field in all the entities, I created a Base Class with the property and getter-setter for 'isActive'. So, during delete, I invoke the update() method and set the isActive to false. I am not able to get this working. If any one has any idea, please let me know. Base Entity public abstract class BaseEntity<TId extends

Is it possible to perform “future” soft delete in laravel?

走远了吗. 提交于 2019-12-25 01:47:00
问题 I found that the soft-delete in laravel Eloquent ORM is just replacing the null in deleted_at column by a timestamp. When querying a table with soft delete, is it just checking if the deleted_at is null, or it is really comparing the value with current time? I am asking to see if I am able to do schedule delete by setting a future time on the deleted_at column. 回答1: Laravel only checks if deleted_at is not NULL . SoftDeletingScope : public function apply(Builder $builder) { $model = $builder-

Method for cascading soft deletes in parent-child relationships

孤人 提交于 2019-12-23 18:30:51
问题 I have a simple schema in which soft deletes are used (that's how it is designed and that can't be changed). There are two tables that participate in the schema: Company (id, is_deleted) and Employee (id, company_id, is_deleted) where company_id ofcourse is a FK to the Company table. The rules are: If a Company has is_deleted = true , then all Employee referring to that company should have is_deleted = true . But an Employee may have is_deleted = true even if the parent Company has is_deleted

How do I Cascade a SoftDelete?

倖福魔咒の 提交于 2019-12-23 12:50:05
问题 After checking these SO articles: cascade-delete-in-entity-framework, ef6-1-soft-delete-with-cascade-delete, cascading-soft-delete, method-for-cascading-soft-deletes-in-parent-child-relationships and reasons-for-cascading-soft-deletes and not finding a solution... I have SoftDelete working for my Entity Models. I have overridden SaveChanges() in my Context: public override int SaveChanges() { ChangeTracker.DetectChanges(); foreach (DbEntityEntry<ISoftDeletable> entity in ChangeTracker.Entries

How to soft delete related records when soft deleting a parent record in Laravel?

こ雲淡風輕ζ 提交于 2019-12-22 01:55:38
问题 I have this invoices table that which has the following structure id | name | amount | deleted_at 2 iMac 1500 | NULL and a payments table with the following structure id | invoice_id | amount | deleted_at 2 2 1000 | NULL Invoice Model class Invoice extends Model { use SoftDeletes; } here's the code to delete the invoice public function cance(Request $request,$id) { $record = Invoice::findOrFail($id); $record->delete(); return response()->json([ 'success' => 'OK', ]); } Payments model class

Cascading Soft Delete

十年热恋 提交于 2019-12-21 06:58:53
问题 SQL has always had a great feature: cascading deletes. You plan it in advance and when it's time to delete something, BAM! No need to worry about all those dependent records. However, nowadays it's almost taboo to actually DELETE anything. You flag it as deleted and stop showing it. Unfortunately, I haven't been able to find a solid solution to doing this when there are dependent records. I've always manually coded the complicated web of soft deletes. Is there a better solution out there that

Entity Framework 5 Soft Delete

北战南征 提交于 2019-12-14 03:57:55
问题 I am trying to prevent any deletes on my database tables. Currently using Entity Framework 5. Firstly here is my code, public override int SaveChanges() { var Changed = ChangeTracker.Entries(); if (Changed != null) { foreach (var entry in Changed.Where(e => e.State == EntityState.Deleted)) { entry.State = EntityState.Unchanged; } } return base.SaveChanges(); } I've managed to prevent it with this way. When i use Remove method of EF its not working anymore.However, what i am trying to achieve

Soft delete an entity in Grails with Hibernate Filters Plugin

南笙酒味 提交于 2019-12-13 15:01:08
问题 I was looking for a way to avoid deleting my users from DB, but instead to mark them as deleted and don't bring them back in queries. I found this plugin http://grails.org/plugin/hibernate-filter, which was a great tool for the task. But when I tried to implement my solution, I passed trought same problems whose solutions wheren't (or I was not able to find) on internet. So, next, I describe the way that I solve the problem of soft delete. 回答1: In this example I will make my class User to

Laravel, Can't update a soft-deleted value

你。 提交于 2019-12-13 01:46:39
问题 I have this values in my db: id - name - created_at - updated_at - deleted_at ------------------------------------------------ 1 - John - 2018-11-11 - 2018-11-11 - (NULL) 2 - John - 2018-11-11 - 2018-11-11 - 2018-11-11 If I search for "John" with my Datatable (Yajra) I only see the John with id=1 because I'm using softdeletes. My model is this: namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class MyModel extends Model { use