Laravel 11: Multi-Tenancy with Multiple Databases

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 เม.ย. 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.com/course/larav...
    - - - - -
    Support the channel by checking out my products:
    - My Laravel courses: laraveldaily.com/courses
    - Filament examples: filamentexamples.com
    - Livewire Kit Components: livewirekit.com
    - - - - -
    Other places to follow:
    - My weekly Laravel newsletter: us11.campaign-archive.com/hom...
    - My personal Twitter: / povilaskorop
  • แนวปฏิบัติและการใช้ชีวิต

ความคิดเห็น • 45

  • @FernandoMartinsdk
    @FernandoMartinsdk หลายเดือนก่อน +1

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

  • @brianochieng5904
    @brianochieng5904 หลายเดือนก่อน

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

  • @shadyardotdev
    @shadyardotdev 3 วันที่ผ่านมา

    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.

  • @pokeripper9707
    @pokeripper9707 หลายเดือนก่อน +1

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

    • @shadyardotdev
      @shadyardotdev 3 วันที่ผ่านมา

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

  • @user-cf5uf7vf2g
    @user-cf5uf7vf2g หลายเดือนก่อน

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

  • @jainsiddharth21
    @jainsiddharth21 22 วันที่ผ่านมา

    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.

  • @RuelLuna
    @RuelLuna หลายเดือนก่อน +3

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

    • @LaravelDaily
      @LaravelDaily  หลายเดือนก่อน +1

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

    • @LaravelDaily
      @LaravelDaily  หลายเดือนก่อน +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 หลายเดือนก่อน +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 หลายเดือนก่อน

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

  • @s.joseph406
    @s.joseph406 หลายเดือนก่อน

    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  หลายเดือนก่อน

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

  • @rishharris8808
    @rishharris8808 หลายเดือนก่อน +6

    Filament 3 with stancl/tenancy

    • @LaravelDaily
      @LaravelDaily  หลายเดือนก่อน +2

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

    • @LaravelDaily
      @LaravelDaily  หลายเดือนก่อน +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.

    • @rishharris8808
      @rishharris8808 หลายเดือนก่อน +1

      @@LaravelDaily yeah with multiple databases thank you so mush

    • @krekas
      @krekas หลายเดือนก่อน

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

    • @meerachaturvedi9050
      @meerachaturvedi9050 หลายเดือนก่อน

      Needed​@@LaravelDaily

  • @discoverlance
    @discoverlance หลายเดือนก่อน

    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  หลายเดือนก่อน +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 หลายเดือนก่อน +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 หลายเดือนก่อน

      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

  • @streakifyapp
    @streakifyapp หลายเดือนก่อน

    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  หลายเดือนก่อน

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

    • @streakifyapp
      @streakifyapp หลายเดือนก่อน +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.

  • @discoverlance
    @discoverlance หลายเดือนก่อน

    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  หลายเดือนก่อน +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 หลายเดือนก่อน +1

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

  • @HossainMdAwlad
    @HossainMdAwlad หลายเดือนก่อน

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

    • @shadyardotdev
      @shadyardotdev 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

  • @junior-dino
    @junior-dino หลายเดือนก่อน +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

    • @hurleyd9828
      @hurleyd9828 หลายเดือนก่อน +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 หลายเดือนก่อน

      @@hurleyd9828 😲

    • @rally_furymoments5294
      @rally_furymoments5294 18 วันที่ผ่านมา

      ​@@hurleyd9828 just curious. Why Django?

  • @dennishalili8090
    @dennishalili8090 หลายเดือนก่อน +1

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

    • @LaravelDaily
      @LaravelDaily  หลายเดือนก่อน

      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 หลายเดือนก่อน

      @@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  หลายเดือนก่อน

      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 หลายเดือนก่อน

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

  • @saidlouham7669
    @saidlouham7669 หลายเดือนก่อน

    First one ❤

  • @nimmneun
    @nimmneun 15 วันที่ผ่านมา

    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 😂