Giter Site home page Giter Site logo

Comments (4)

stancl avatar stancl commented on June 12, 2024 1

Please take a look at how Eloquent works under the hood. This has nothing to do with tenancy.

$user->tenants()->delete() doesn't delete databases because it also doesn't trigger events. Laravel doesn't fetch each tenant to delete it individually here, it instead tells the SQL server to bulk delete tenants that match certain filters.

To delete a user's tenants with databases, you'd need to first fetch the model instances before calling delete() on them individually.

from tenancy.

stancl avatar stancl commented on June 12, 2024

SQL servers can't run PHP. If you use ON DELETE CASCADE, it will be the SQL server deleting the tenant record, not Laravel. Therefore none of Laravel's events will be fired.

I'd suggest using Laravel's events to delete the tenant record instead of CASCADE.

from tenancy.

skills-up avatar skills-up commented on June 12, 2024

The issue persists even without ON DELETE CASCADE.

I've called the following:

$user->tenants()->delete();
$user->delete();

The tenant gets deleted, along with associated domains. But the tenant DB remains intact.

from tenancy.

skills-up avatar skills-up commented on June 12, 2024

Thanks @stancl
This solved the issue. Apologies for making assumptions regarding delete events getting triggered on collection.

from tenancy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.