How to delete images if exists when cascade operation happens in Laravel 8?

Viewed 28

How or where to add some code to help Laravel to delete products' images which related to the deleted sub category record when using Laravel CASCADE?

Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('sub_category_id');
    $table->foreign('sub_category_id')->references('id')->on('sub_categories')->onDelete('CASCADE');
    $table->text('description');
    $table->double('price');
    $table->string('image');
    $table->timestamps();
});

Note that: I upload images to 'public/' path.

0 Answers
Related