Laravel 11: Multi-Tenancy with Multiple Databases

Поділитися
Вставка
  • Опубліковано 20 жов 2024
  • We upgraded the course on multi-tenancy to Laravel 11. Let's see how to set up multiple databases for it, with stancl/tenancy package.
    Full course: laraveldaily.c...
    - - - -
    Support the channel by checking out my products:
    My Laravel courses: laraveldaily.c...
    Filament examples: filamentexampl...
    Livewire Kit Components: livewirekit.com
    - - - -
    Other places to follow:
    My weekly Laravel newsletter: us11.campaign-...
    My personal Twitter: / povilaskorop

КОМЕНТАРІ • 55

  • @brianochieng5904
    @brianochieng5904 6 місяців тому +1

    Video quality has been top notch ever since you got the machine. May God continue blessing you Povilas.

  • @FernandoMartinsdk
    @FernandoMartinsdk 6 місяців тому +4

    I can't tell you how much this video helped me. Thank you very much.

  • @pokeripper9707
    @pokeripper9707 6 місяців тому +3

    I am using this package for a pretty large project. It works really great!

    • @techwithshadyar
      @techwithshadyar 4 місяці тому

      Sorry for the replay, but are you using it with api SPA or just laravel?

  • @techwithshadyar
    @techwithshadyar 4 місяці тому +2

    Thanks for this video. You didn't discuss what changes if you're using it with an API, like a Vue SPA, with the package. Also, what's the best way to identify a tenant? Should you send the subdomain with every request, or is there another recommended approach?
    If you can provide some explanation, I'd appreciate it.

  • @RuelLuna
    @RuelLuna 6 місяців тому +4

    Would be interested to see how Filament v3 Panels integrate with stancl/tenancy

    • @LaravelDaily
      @LaravelDaily  6 місяців тому +1

      Added to the list of topics, but probably on my other Filament Daily channel, then.

    • @LaravelDaily
      @LaravelDaily  6 місяців тому +2

      Hi, we were planning to shoot a video about Filament with stancl/tenancy but concluded that this package is needed ONLY in case that you want to have multiple databases. Which is, in my opinion, a pretty rare case. So just wanted to ask you back: are you really planning multiple databases in your projects and need a video about it?
      I just personally don't want to spend a lot of time on video that will be needed only for like 3 people.

    • @RuelLuna
      @RuelLuna 6 місяців тому +1

      @@LaravelDaily Yes, multi-databases. People are finding it online too. I have a product that needs to be re-coded using both in multi-databases. My problem roots as to how to configure the central and tenant routes. There isn't much guide there. There are sample gists but needed failed to implement them. Anyhow, if it doesn't seem to be a video-worthy, that's okay. But it's fairly watchable I must say.

    • @nixonsampson8645
      @nixonsampson8645 5 місяців тому

      ​@@LaravelDailyto me definitely have a Fintech product to run I think it will help a lot can't wait to see a notification from you sir

    • @srdjanmarjanovic
      @srdjanmarjanovic 12 днів тому

      +1 for this! I need for whitelabel saas product so multi-database approach is a must! I would be so grateful for video on how to set up Filament v3 with stancl/tenancy

  • @usmanibraheem8377
    @usmanibraheem8377 12 днів тому

    Great Video. I'm having one issue using with inertia. for a central domain. it get route of last central domain in the list. for example main.local and main.test are 2 central domains. for central domain routes it use the last one (main.test) even if I'm accessing through other domain(main.local). it happen for central domain routes only. not for shared routes between central domain and tenants

  • @streakifyapp
    @streakifyapp 6 місяців тому +1

    I think one huge aspect of having 1 shared database that you've missed is performance, it means a single tenant with a million records would slow down database reads and queries for all tenants? I guess indexes on the tenant_id in there where claus would help with that but I still imagine they'd be performance implications?

    • @LaravelDaily
      @LaravelDaily  6 місяців тому

      I did mention it but maybe didn't emphasize enough from that angle, thanks for the valuable comment.

    • @streakifyapp
      @streakifyapp 6 місяців тому +1

      @@LaravelDaily apologies my mistake, you do mention it briefly :) thanks for your reply.
      Having setup this package on an existing project with varying amounts of data, the separation for performance and isolation reasons was definitely ideal for me, and you could argue for others who intend to scale, but as mentioned I would be curious to see if performance is an issue on a shared DB that has proper indexes setup, I imagine it would be.
      The package also helps negate the side effects of multi-db with great migration support etc.

  • @DibakarKhamrui
    @DibakarKhamrui Місяць тому

    tenant get and post route name not defined error but resource route name working how to solved it

  • @jainsiddharth21
    @jainsiddharth21 5 місяців тому

    Hi, Great tutorial. I've used Tenancy with Multi Tenant & single DB. I need a functionality to ghost login my admin as a tenant user. Could you help me out with that please, if possible.

  • @user-cf5uf7vf2g
    @user-cf5uf7vf2g 5 місяців тому

    i tested few packages, end up multi database setting with tedious auth implementation between login from landlord and tenant.

  • @getupkid84
    @getupkid84 2 місяці тому +1

    Is it just me? or does the documentation on stancl/tenancy package seem to be a little bit all over the place?

    • @LaravelDaily
      @LaravelDaily  2 місяці тому +1

      The subject itself is hugely complex. It's hard to write the documentation that would NOT be all over the place. And you can contribute to it!

  • @discoverlance
    @discoverlance 6 місяців тому

    Is it possible to setup multi tenancy without assigning domains to each tenant? I suppose not but that's always a concern for me but i haven't really dived into it to get more details just yet.

    • @LaravelDaily
      @LaravelDaily  6 місяців тому +2

      Yes it's possible, but then you need to define your own rules how to define which tenant is active. It's all in the docs of the package.

    • @streakifyapp
      @streakifyapp 6 місяців тому +1

      Yep, "tenant identification" can be achieved with domains, subdomains, paths and request data, see the docs/v3/tenant-identification

  • @s.joseph406
    @s.joseph406 6 місяців тому

    Nice one, but my concern is on jobs and queue, will they not be affected by having different databases. What are the effects of using multiple databases ? Does it limit the any functionalities in laravel ?

    • @LaravelDaily
      @LaravelDaily  6 місяців тому

      You can run the queue for the central database, or tenant databases separately with different queue workers, depending on how you configure it.

  • @dennishalili8090
    @dennishalili8090 5 місяців тому +2

    Hello, can you please make a video about Filament 3: Multi Tenancy File Upload? Thanks.

    • @LaravelDaily
      @LaravelDaily  5 місяців тому

      What exactly is the problem with this file upload? Seems like it's all in the docs, what exactly doesn't work or is unclear for you?

    • @dennishalili8090
      @dennishalili8090 5 місяців тому +1

      @@LaravelDaily Thanks for your response.
      I have tenants table to handle the tenancy.
      As per documentation, tenancyforlaravel
      Since storage_path() will be suffixed, folder structure will look like this:
      IDEAL Directory
      /storage
      /storage/tenant1/app/public/logo.png
      /storage/tenant1/app/public/projects/....jpg
      /storage/tenant2/app/public/logo.png
      /storage/tenant2/app/public/projects/....jpg
      But during saving, => [2024-05-01 10:43:32] local.ERROR: file_put_contents(/Users/dennishalili/Web Development/JohnDoe/sample-project/storage/tenant2/framework/cache/facade-1e06026dbe325cba543b2306bd7e55d66d31e4c1.php): Failed to open stream: No such file or directory {"userId":3,"exception":"[object] (ErrorException(code: 0): file_put_contents(/Users/dennishalili/Web Development/JohnDoe/sample-project/storage/tenant2/framework/cache/facade-1e06026dbe325cba543b2306bd7e55d66d31e4c1.php): Failed to open stream: No such file or directory at /Users/dennishalili/Web Development/JohnDoe/sample-project/vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php:107)
      I set the permission of storage folder into 755, 775 and 777 but no luck.
      New/Regular Filament project(not multi Tenancy, has a smooth File Upload)
      Manual Process: I tried to create folder in order to move forward. "/storage/tenant2/framework/cache/" and another error came up after this when I tried to save the record.
      => Error if framework/cache folder manually created.
      [2024-05-01 10:47:11] local.ERROR: Unable to retrieve the file_size for file at location: livewire-tmp/maGCL0oSjtqgcNSe8nIsJ1mfkBBG5M-metac2FtcGxlLW9mZmljZS1kZXNpZ24ucG5n-.png. {"userId":3,"exception":"[object] (League\\Flysystem\\UnableToRetrieveMetadata(code: 0): Unable to retrieve the file_size for file at location: livewire-tmp/maGCL0oSjtqgcNSe8nIsJ1mfkBBG5M-metac2FtcGxlLW9mZmljZS1kZXNpZ24ucG5n-.png. at /Users/dennishalili/Web Development/JohnDoe/sample-project/vendor/league/flysystem/src/UnableToRetrieveMetadata.php:49)
      Disk is PUBLIC.

    • @LaravelDaily
      @LaravelDaily  5 місяців тому

      Thanks for taking the time. But wow it sounds like a specific case for your individual problem with filesystem.
      To be honest, I'm not sure why people use tenancyforlaravel package on top of default Filament 3 multi tenancy. Is it for multiple databases, just for that?
      Cause then you're getting these weird errors when trying to mix two packages that don't really know about each other's settings.

    • @dennishalili8090
      @dennishalili8090 5 місяців тому

      @@LaravelDaily Very much appreciated your reply. Thank you for your videos here in youtube, I can't tell you how much your videos helped me. God bless.

  • @junior-dino
    @junior-dino 6 місяців тому +4

    Once upon a time I've tried to do that on my own & after trying for couple of weeks, I found myself nowhere near that project 🙃 It felt too complicated

    • @brazenbull36
      @brazenbull36 6 місяців тому +2

      I've been working on one for two years (Django), maintaining multiple DBs take a lot of effort. Kinda streeeful

    • @junior-dino
      @junior-dino 6 місяців тому

      @@brazenbull36 😲

    • @rally_furymoments5294
      @rally_furymoments5294 5 місяців тому

      ​@@brazenbull36 just curious. Why Django?

  • @discoverlance
    @discoverlance 6 місяців тому

    How does multiple domains affect generating urls in the app, for example, i would usually set an APP_URL to my site's domain in my .env which is useful for generating urls in tthe app, how does multi tenancy in this case affect it or url generations with route or url helper functions?

    • @LaravelDaily
      @LaravelDaily  6 місяців тому +1

      It depends on the situation: depending on how you write code, you may access both main .env APP_URL or the domain of the tenant.

    • @pokeripper9707
      @pokeripper9707 6 місяців тому +2

      In your main database you can setup tenants, and add domains to it. Then you can set a primary domain to the tenant. And the package is smart enough to automatically pick the correct urls.

    • @streakifyapp
      @streakifyapp 6 місяців тому

      You would have your base domain for your "central" database, this has a table which domains link to which tenants, also each tenant has their own ability to override .env values so that each tenant can have relative values

  • @rishharris8808
    @rishharris8808 6 місяців тому +8

    Filament 3 with stancl/tenancy

    • @LaravelDaily
      @LaravelDaily  6 місяців тому +2

      Added to the list of topics, but probably on my other Filament Daily channel, then.

    • @LaravelDaily
      @LaravelDaily  6 місяців тому +2

      Hi, we were planning to shoot a video about Filament with stancl/tenancy but concluded that this package is needed ONLY in case that you want to have multiple databases. Which is, in my opinion, a pretty rare case. So just wanted to ask you back: are you really planning multiple databases in your projects and need a video about it?
      I just personally don't want to spend a lot of time on video that will be needed only for like 3 people.

    • @rishharris8808
      @rishharris8808 6 місяців тому +3

      @@LaravelDaily yeah with multiple databases thank you so mush

    • @krekas
      @krekas 6 місяців тому

      ​@rishharris8808, but why do you need multiple db? What's the use case that can't be done with single?

    • @meerachaturvedi9050
      @meerachaturvedi9050 5 місяців тому

      Needed​@@LaravelDaily

  • @HossainMdAwlad
    @HossainMdAwlad 5 місяців тому

    What happenes if central domain and tenants have separate user tables?

    • @techwithshadyar
      @techwithshadyar 4 місяці тому

      If you mean for authentication, then you need to define a guard alongside a provider in config auth for it also create a middleware to change the guard if it's tenant context

  • @manu144x
    @manu144x 2 місяці тому

    I really tried to use that package but I hate the fact he makes the tenant database migrations in a separate folder instead of the main one.
    Also the routes separation for tenant and central database.
    In my own implementation the application is identical for all tenants, there is no main database, or if it is, it just has some extra authorization logic to make sure it's the admin tenant, very straightforward.
    My plan is to simply have another laravel instance to manage the tenants, I don't want to have all this risks of separate implementations for tenants vs central application. All my routes, everything is identical. I just have some middleware and providers that switch context for them, that's it.

    • @getupkid84
      @getupkid84 2 місяці тому

      You rolled your own multi tenancy with multi databases?

    • @manu144x
      @manu144x 2 місяці тому

      @@getupkid84 Yes, I needed it 10 years ago.

  • @MinKhant-x4l
    @MinKhant-x4l Місяць тому

    Hello , Could you make me tutorial multi tenancy and multi database in filament and laravel 11?

    • @LaravelDaily
      @LaravelDaily  Місяць тому +1

      I will probably wait for Filament 4 release to create something that big

  • @nimmneun
    @nimmneun 4 місяці тому +1

    Nice 👍 Things are all nice and dandy until you have the first tenants uploading millions of products where every pack of 5, 10, 20, 50, 100, 500 is a separate SKU and you're like uh ... that table had 20 million records last year, now its 700 million etc 😂

  • @saidlouham7669
    @saidlouham7669 6 місяців тому

    First one ❤