Lädt...


🔧 Filament: Delete Attachments when Deleting a Record


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Filament allows you to add attachments to a record, but doesn’t delete them when you delete the record.

In order to solve this issue, we have two alternatives:

Listen to model’s deleting event

When a model it’s about to be deleted, it fires the deleting event. We can listen to this event to trigger the functionality responsible to delete any attachements before the model no longer exists.

Inside the model class we can add the booted method to register new event listeners to the model.

class Project extends Model
{
    protected $fillable = [
        'title', 'slug', 'repository', 'description', 'thumbnail',
    ];

    /**
     * The "booted" method of the model.
     */
    protected static function booted(): void
    {
        static::deleting(function ($project) {
            Storage::disk('public')->delete($project->thumbnail);
        });
    }
}

This code will delete the thumbnail attachment before deleting the model.

You can read more about this in the Laravel documentation https://laravel.com/docs/11.x/eloquent#events-using-closures

Modify Filament’s delete action

Another option is to change the behaviour of the delete action.

protected function getActions(): array
{
    return [
        Actions\DeleteAction::make()
            ->after(function (Project $project) {
                // delete single
                if ($project->thumbnail) {
                    Storage::disk('public')->delete($project->thumbnail);
                }
            })
    ];
}

You can use the option better fits your requirements, but you should keep in mind that adding an event listener will delete the attachment when your model is deleted, whenever has occured by a Filament action or another part of code in your app.

This is important because probably will determine whenever option you should choose.

...

🔧 Filament: Delete Attachments when Deleting a Record


📈 67.84 Punkte
🔧 Programmierung

🕵️ CVE-2024-42485 | pxlrbt filament-excel up to 2.3.2 /filament-excel/{path} path traversal


📈 36.97 Punkte
🕵️ Sicherheitslücken

🕵️ Nextcloud: Ownership check missing when updating or deleting attachments


📈 31.03 Punkte
🕵️ Sicherheitslücken

🔧 To Delete a record without using the DELETE | INSERT | UPDATE


📈 27.85 Punkte
🔧 Programmierung

🎥 Delete and download post attachments - Part 11 | Laravel Social Media Website


📈 25.05 Punkte
🎥 Video | Youtube

🕵️ PostfixAdmin bis 3.0.1 AliasHandler delete.php gen_show_status() delete Denial of Service


📈 19.04 Punkte
🕵️ Sicherheitslücken

🔧 C++ 為什麼要有 delete 和 delete[]


📈 19.04 Punkte
🔧 Programmierung

🐧 How to Delete Ingress Using “kubectl delete” Command?


📈 19.04 Punkte
🐧 Linux Tipps

🔧 A Guide for Delete Pods from Kubernetes Nodes - kubectl delete


📈 19.04 Punkte
🔧 Programmierung

🔧 Delete YouTube History – How to Delete YouTube Search and Watch Histories


📈 19.04 Punkte
🔧 Programmierung

📰 What is Alt Control Delete on Macbook? 5 Ways to Perform Control+Alt+Delete


📈 19.04 Punkte
📰 IT Security Nachrichten

🍏 How to Delete Apps on Mac that Won’t Delete


📈 19.04 Punkte
🍏 iOS / Mac OS

🪟 Can’t Delete Folder? How to Force Delete Folder in Windows 10


📈 19.04 Punkte
🪟 Windows Tipps

🐧 How To Delete WhatsApp Group: Exit And Delete A Group


📈 19.04 Punkte
🐧 Linux Tipps

🕵️ PostfixAdmin up to 3.0.1 AliasHandler delete.php gen_show_status delete denial of service


📈 19.04 Punkte
🕵️ Sicherheitslücken

🕵️ WhatsApp Privacy Flaw – Delete for Everyone Feature Fails to Delete Media from iPhone


📈 19.04 Punkte
🕵️ Hacking

📰 WhatsApp 'Delete for Everyone' Doesn't Delete Media Files Sent to iPhone Users


📈 19.04 Punkte
📰 IT Security Nachrichten

🐧 Find and delete all files in folder, but don't delete the folder itself


📈 19.04 Punkte
🐧 Linux Tipps

📰 Zombie Cloud Data: What Your Delete Key May Not Delete


📈 19.04 Punkte
📰 IT Security Nachrichten

📰 TechStage | UV-Harz oder Kunststoff-Filament: 3D-Drucker im Vergleich


📈 18.48 Punkte
📰 IT Nachrichten

🔧 Laravel Nova vs Filament: The Best Admin Panels


📈 18.48 Punkte
🔧 Programmierung

📰 heise+ | Wie man einen Lichtleiter aus 3D-Druck-Filament erstellt


📈 18.48 Punkte
📰 IT Nachrichten

📰 TechStage | Das beste Filament für 3D-Drucker: 14 Sorten PETG im Test


📈 18.48 Punkte
📰 IT Nachrichten

🔧 Laravel Filament: get resource table data by authenticated id


📈 18.48 Punkte
🔧 Programmierung

📰 Ultimaker S3: Endlich Filament-Flow-Sensoren


📈 18.48 Punkte
📰 IT Nachrichten

🔧 Add a sidebar with options in a Filament resource


📈 18.48 Punkte
🔧 Programmierung

📰 3D-Druck: Fachhochschule Münster stellt Filament selbst her


📈 18.48 Punkte
📰 IT Nachrichten

🔧 Customize Filament Table Query


📈 18.48 Punkte
🔧 Programmierung

📰 Signify: Neue Philips-Hue-Filament-Lampen vorgestellt


📈 18.48 Punkte
📰 IT Nachrichten

🔧 Filament: Add icon to form buttons


📈 18.48 Punkte
🔧 Programmierung

📰 Epic Games Store: „Filament“ und „Rising Storm 2: Vietnam“ kostenlos zu haben


📈 18.48 Punkte
📰 IT Nachrichten

matomo