6 months ago

Doing something before delete in Eloquent Models Even in mass deleting

Posted 6 months ago by m.f.rasoulnejad

hi. I have a model like 'Product' it has a field called 'photo'. I want to delete its photo file from my disk every time i delete a product from too. this is a really simple task like so:

namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
    public function delete()
        return parent::delete();

But when I mass delete these products like this:

$products= Product::whereRaw('FIND_IN_SET(?,category)', [$someCategoryObject->id]);

its not deleting the photo file of these products. whats wrong? I'm new in laravel and this made me angry for a whole freaking day!! haha.

Please sign in or create an account to participate in this conversation.