Laravel 11: Multi-Tenancy with Multiple Databases

Поделиться
HTML-код
  • Опубликовано: 21 сен 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

Комментарии • 53

  • @brianochieng5904
    @brianochieng5904 5 месяцев назад +1

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

  • @pokeripper9707
    @pokeripper9707 5 месяцев назад +2

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

    • @learnwithshadyar
      @learnwithshadyar 3 месяца назад

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

  • @FernandoMartinsdk
    @FernandoMartinsdk 5 месяцев назад +2

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

  • @learnwithshadyar
    @learnwithshadyar 3 месяца назад +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 5 месяцев назад +3

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

    • @LaravelDaily
      @LaravelDaily  5 месяцев назад +1

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

    • @LaravelDaily
      @LaravelDaily  5 месяцев назад +1

      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 5 месяцев назад +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 4 месяца назад

      ​@@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

  • @DibakarKhamrui
    @DibakarKhamrui 29 дней назад

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

  • @streakifyapp
    @streakifyapp 5 месяцев назад

    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  5 месяцев назад

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

    • @streakifyapp
      @streakifyapp 5 месяцев назад +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.

  • @junior-dino
    @junior-dino 5 месяцев назад +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 5 месяцев назад +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 5 месяцев назад

      @@brazenbull36 😲

    • @rally_furymoments5294
      @rally_furymoments5294 4 месяца назад

      ​@@brazenbull36 just curious. Why Django?

  • @manu144x
    @manu144x Месяц назад

    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 Месяц назад

      You rolled your own multi tenancy with multi databases?

    • @manu144x
      @manu144x Месяц назад

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

  • @jainsiddharth21
    @jainsiddharth21 4 месяца назад

    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 4 месяца назад

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

  • @getupkid84
    @getupkid84 Месяц назад

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

    • @LaravelDaily
      @LaravelDaily  Месяц назад

      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!

  • @s.joseph406
    @s.joseph406 5 месяцев назад

    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  5 месяцев назад

      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 4 месяца назад +1

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

    • @LaravelDaily
      @LaravelDaily  4 месяца назад

      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 4 месяца назад

      @@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  4 месяца назад

      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 4 месяца назад

      @@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.

  • @rishharris8808
    @rishharris8808 5 месяцев назад +7

    Filament 3 with stancl/tenancy

    • @LaravelDaily
      @LaravelDaily  5 месяцев назад +2

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

    • @LaravelDaily
      @LaravelDaily  5 месяцев назад +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 5 месяцев назад +2

      @@LaravelDaily yeah with multiple databases thank you so mush

    • @krekas
      @krekas 5 месяцев назад

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

    • @meerachaturvedi9050
      @meerachaturvedi9050 4 месяца назад

      Needed​@@LaravelDaily

  • @MinKhant-x4l
    @MinKhant-x4l 28 дней назад

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

    • @LaravelDaily
      @LaravelDaily  28 дней назад

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

  • @discoverlance
    @discoverlance 5 месяцев назад

    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  5 месяцев назад +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 5 месяцев назад +1

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

  • @discoverlance
    @discoverlance 5 месяцев назад

    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  5 месяцев назад +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 5 месяцев назад +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 5 месяцев назад

      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

  • @HossainMdAwlad
    @HossainMdAwlad 4 месяца назад

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

    • @learnwithshadyar
      @learnwithshadyar 3 месяца назад

      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

  • @nimmneun
    @nimmneun 3 месяца назад

    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 5 месяцев назад

    First one ❤