Laravel Code Review: Multi-Tenancy, Events and Queues

Поделиться
HTML-код
  • Опубликовано: 1 июл 2024
  • Another code review, this time it's not junior code: it's an interesting multi-tenancy and multi-DB solution, with events and listeners.
    00:00 Intro
    00:57 Install: Readme and .env.example
    03:20 Sign Up: How Multi-Tenancy Works
    06:08 Let's Try it Out
    06:41 Bug: .env and config
    08:15 Tenant Routes: IT WORKS!
    09:30 Validation and Subdomain
    10:20 Two Events and Two Listeners?
    11:01 Events or Jobs and Queues?
    12:30 Why Artisan Command?
    Laravel Envoyer SaaS Generator Repository: github.com/LaravelDaily/Larav...
    - - - - -
    Support the channel by checking out our products:
    - Try our Laravel QuickAdminPanel: bit.ly/quickadminpanel
    - Enroll in my Laravel courses: laraveldaily.teachable.com
    - Purchase my Livewire Kit: livewirekit.com
    - Subscribe to my weekly newsletter: bit.ly/laravel-newsletter
  • ХоббиХобби

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

  • @urvishpatel6105
    @urvishpatel6105 3 года назад +3

    I learned a lot from your videos regarding code standards and all. You are doing such great work. Thank you Povilas for giving your contribution to the laravel community. Great work. Keep it up.

  • @jeevachaithanyansivanandan
    @jeevachaithanyansivanandan 3 года назад +2

    The way you read and breakdown the codebase is like a Symphony performance... Thankx for the video

  • @igbokwelaurence5882
    @igbokwelaurence5882 3 года назад +2

    Good review as always. And very nice work done by this developer.

  • @mohammadoulabi4212
    @mohammadoulabi4212 3 года назад +19

    Overall the code was amazing and your review tought me like hundred new thing
    Just wow

  • @TheMarvelsWorld
    @TheMarvelsWorld 3 года назад

    This is really amazing. It helps me a lot

  • @topx777
    @topx777 3 года назад

    Thanks a lot for that advices, that a good point of view for everyone

  • @TristanBailey
    @TristanBailey 3 года назад +2

    That was a good breakdown

  • @heyyy4987
    @heyyy4987 3 года назад

    Very Nice, and touch many ways of do it same thing.

  • @AndyTalbot
    @AndyTalbot 3 года назад +6

    Can't believe this was from 3 months ago and I missed it. Looks like a great project, well done that developer. One thing I was surprised you didn't mention was the importance of using config variables rather than env ones direct, because once you go to a production environment you should really be running config:cache, at which point all the env based bits stop working.

    • @JamesAutoDude
      @JamesAutoDude 2 года назад +1

      Wait really? This is the first I've heard of that... Almost all projects I've came across just says to use the env file
      I read the Laravel docs and it says that's only to speed up the application, doesn't say it's good practice or anything

    • @AndyTalbot
      @AndyTalbot 2 года назад

      @@JamesAutoDude I think anything that has to access and read a file could be deemed slow, better to cache it to redis or something.
      I also found that locally on windows when running Apache, if you have a page which on load immediately performs say 2 API calls to the server. The .env file will be locked presumably by windows from the first call, and it causes laravel to return a 500 error. Only way I found to get around this locally was to cache the config. Which if you're using the file driver makes no sense, but somehow seems to resolve it.

    • @JamesAutoDude
      @JamesAutoDude 2 года назад

      @@AndyTalbot uhhh you do know that cache is reading a file right 😬 websites general are nothing but files... I'd have to disagree as I have big applications and even tried huge Laravel projects,a they were blazing fast using just the .env

    • @AndyTalbot
      @AndyTalbot 2 года назад

      @@JamesAutoDude redis isn't files is it? That's memory based I thought. But yes otherwise file based caching should in theory still be the same problem as the .env I think windows based Apache might be a bit odd and doing some kind of blocking.

  • @ayubadauda5295
    @ayubadauda5295 3 года назад

    Thanks for the review, Using this pattern, is there a way we can scale up for a single tenant?

  • @lucchateauvert330
    @lucchateauvert330 2 года назад

    Super interesting, thanks for this review. I noticed in the mapTenantRoutes function a reference to subdomain and saw that the subdomain was not used in the tenant routes file to wrap the routes. My question is, where comes from the subdomain value? Thanks!

  • @rism8345
    @rism8345 Год назад

    Great review

  • @khanalpride
    @khanalpride 3 года назад

    Interesting.
    Events/Listeners are great as well.
    And they focus on things where one event can be used to fire different Listeners.
    You said to use Job as they are queueable.
    But the fact is Event is only fired. And most time consuming things are done in Listeners (which are obviously queueable)

  • @thisisthelogic
    @thisisthelogic 3 года назад

    You're the best!

  • @fajarsetiawansiagian
    @fajarsetiawansiagian 3 года назад

    thats review of code make me understand to make each other can read my code

  • @ahmad.ms96
    @ahmad.ms96 2 года назад

    thanks , do you suggest a specific multi tenant package to use ?

  • @thebollyhollymix
    @thebollyhollymix 3 года назад

    Can we use fqdn example.test instead of subdomains?

  • @user-bq9yy3bt9k
    @user-bq9yy3bt9k 3 года назад

    Hi!
    Why events? isnt it easier to use observer? and call queue from observer

  • @hadesinferno813
    @hadesinferno813 Год назад

    How do you set your database connection for each tenant?

  • @veds-art-world
    @veds-art-world 10 месяцев назад

    Can you create tests for GitHub CI in multiple sub domain?

  •  3 года назад

    09:30
    line 52: should go to FormRequest->authorize (user->can('create_project') or route middleware (can:create_project)
    line 58, 59, 60: not needed
    line 61: should go to static boot of Models\Project. Something like that: static::creating( fn ($project) => $project->created_by_id = auth()->id() );
    Also, it advised to pass the guard to auth() since he/she's probably implementing multi guard authentication.

  • @hadesinferno813
    @hadesinferno813 Год назад

    If you were to run a migration in a job, how would you do that?
    What if a job fails, how do you catch the exception and display the error.

  • @naviji7306
    @naviji7306 3 года назад

    Hi, can you please create video on laravel installation like cms WordPress and Drupal etc
    Configure db details etc from browser form

  • @badeamihai
    @badeamihai 3 года назад

    Hi,
    I have a web application built on Laravel for document management with an integration with CSC API from where I get a hashed signature. I am wondering if you have a solution for adding this signature to the pdf. I don't have access to the private or public keys, they are stored in the cloud and the certificate as well.
    Thank you

    • @LaravelDaily
      @LaravelDaily  3 года назад +1

      Sorry I haven't worked with such projects or CSC API, so I have no advice.

  • @alexo2537
    @alexo2537 2 года назад

    Is it possible to make a tutorial with multi-databases and multi-tenants but always keeping the same base URL and not putting in the URL the subdomain ? For example my domain is project.test and from project.test/login I can identify which tenant I belong to without placing a subdomain of the account.

  • @aloha276
    @aloha276 3 года назад

    A question please,
    Since this project is using subdomains to get the database name, do you have any idea on how to get the right database in case we connect this project to a mobile app using a REST API ?

    • @aloha276
      @aloha276 3 года назад

      @Ahmed Safaa Thanks for your help!

  • @GergelyCsermely
    @GergelyCsermely 3 года назад

    Interesting

  • @enriquerobledo845
    @enriquerobledo845 3 года назад

    Very interesting, a course of this topic multitenancy saas, would be a very good one, i'm willing to buy the yearly membership, maybe this idea of new course can be a thing

    • @LaravelDaily
      @LaravelDaily  3 года назад +2

      laraveldaily.teachable.com/p/creating-laravel-saas-with-cashier-stripe I have a SaaS course, MultiTenancy is one of the lessons there, from what I remember

    • @devstack6420
      @devstack6420 2 года назад

      @@LaravelDaily Hello sir, this course including create new database like this video? thanks.

  • @NathanBudd
    @NathanBudd 3 года назад

    What would be the differnce here between using a listener and a model observer which fires a job on create?

    • @LaravelDaily
      @LaravelDaily  3 года назад +2

      Personal preference.

    • @pauloamserrano
      @pauloamserrano 3 года назад +2

      @@LaravelDaily Without a doubt between listeners and observers is a personal preference, however I reformulated that part of the project to use queues and came to the conclusion that jobs must be used, for the simple reason that in queue, listeners are not used chaining, which sometimes caused error because the migrations listener was triggered before the database was created. With jobs and queue chains this problem is solved, because we can chain jobs and the second is triggered only when the first one finishes successfully.

  • @adityakadam2256
    @adityakadam2256 3 года назад

    How does it work for sub domain routing? Don’t we need to create separate DNS record for each subdomain on live servers like Route53?

    • @corneveldman3494
      @corneveldman3494 3 года назад +1

      You can wildcard subdomains

    • @DeteCT0R
      @DeteCT0R 3 года назад

      If you have project like this consider using cloudflare. They have php api so you can create subdomain. Wildcard is good for local testing.

    • @MarkSnape
      @MarkSnape 3 года назад +1

      All subdomain requests come to the same Laravel installation. The application then detects which subdomain the request was for.

  • @rizhuljanuar1618
    @rizhuljanuar1618 3 года назад

    Sir, know how to use the laravel telescope without migrate, because the database has been provided

    • @LaravelDaily
      @LaravelDaily  3 года назад

      Telescope has nothing to do with migrations, from what I understand. What functionality of telescope you want to use exactly?

  • @casapvadim
    @casapvadim 3 года назад +1

    For database name as a question or suggestion!
    - How do you think, to use some generated text from backends like: project id, or timestamp, or random string ( of course validating before if necessary)
    Also, there is a point in 5:30 with setConnection with a project id, looks like multitenancy is custom if it's possible to take a look at that connection if there is a used multi user or everything is running under the main database user.
    I found a good package from spatie spatie.be/docs/laravel-multitenancy/v2/installation/using-multiple-databases
    but didn't check it yet
    sorry if I repeated some else's question and hope not to disturb you ^_^ nice job

    • @LaravelDaily
      @LaravelDaily  3 года назад +3

      Yes, to be honest, I would use one of the available multi tenancy packages instead of doing it manually. Probably should have mentioned this in the video.

  • @rudolfbruder4674
    @rudolfbruder4674 3 года назад +1

    First, Thank you for content!

  • @alila3883
    @alila3883 2 года назад

    🤙

  • @aytacmalkoc
    @aytacmalkoc 3 года назад +6

    Hi, you have censored the information of the person who sent the email, but the email address appears in the search bar of the browser.

    • @LaravelDaily
      @LaravelDaily  3 года назад +13

      Thanks, damn, I miss those things from time to time. Edited the video, RUclips is processing the changes now. Thanks for reporting, I need to be more careful.

    • @pauloamserrano
      @pauloamserrano 3 года назад +16

      @@LaravelDaily Hi Povilas, I'm the author... is not problem with that.

    • @casapvadim
      @casapvadim 3 года назад +2

      @@pauloamserrano nice job

    • @igbokwelaurence5882
      @igbokwelaurence5882 3 года назад

      @@pauloamserrano good job man. Is the project open source or a client. There's a lot of things I'd like to learn from that codebase

    • @pauloamserrano
      @pauloamserrano 3 года назад +2

      @@igbokwelaurence5882 email me. pauloamserrano@gmail.com

  • @sarangbelsare7176
    @sarangbelsare7176 3 года назад

    Hello sir
    Can you please provide the code to get some help about multi-tenancy?

    • @LaravelDaily
      @LaravelDaily  3 года назад +2

      Which code do you need? If you want the code of that specific repository, then I can't give you that, because it's not my code and it's not public.

    • @igbokwelaurence5882
      @igbokwelaurence5882 3 года назад

      @@LaravelDaily do you have any multi tenancy tutorial available Sir ?

  • @shocchosolutions6275
    @shocchosolutions6275 3 года назад

    how to upload laravel app in shared hosting

    • @LaravelDaily
      @LaravelDaily  3 года назад +2

      I don't recommend shared hosting for any Laravel project.

    • @windigo000
      @windigo000 3 года назад

      i use wz.cz ... in their file manager one can unzip package. commands can be run by simple routes. BE VERY CAREFULL WITH THAT. secure everything.
      it's easies to migrate localy and import db struct through sql manager.
      there might be issue with rewrite ... check hosting q&a or ask CS ;)

    • @windigo000
      @windigo000 3 года назад

      also... run composer before upload to get rid of dev packages. you don't need them.

    • @poplach
      @poplach 3 года назад +1

      Make a new laravel project on local machine, then run composer require without --dev, run migrations. Then upload everything on shared hosting and export/import mysql databases separately.
      Here you go - everything running.
      The problem is only with artisan commands - you don't have access to a console - so you can't run artisan commands. Everything else runs great. Tested bagillion times. Laravel can be run on shared hosting, but I'd recommend only really small projects to run on that. Since when the time comes to update your project - it will be VERY uncomfortable to do that.
      Oh yeah, forgot to mention that all your QUEUED JOBS won't work at all, since the listener won't work as well. So forget about queued jobs too

  • @meerachaturvedi9050
    @meerachaturvedi9050 2 года назад

    There is no tenent.php in config

  • @JamesAutoDude
    @JamesAutoDude 2 года назад

    How the heck do you know all of this 😭 there's so many damn files with Laravel that I constantly get confused!

  • @nishantgupta1854
    @nishantgupta1854 3 года назад

    can i get a download link for this project.

  • @newtoys5593
    @newtoys5593 Год назад

    You are the best but I don't like you have mixed to many topics in one lesson.

  • @simbarashemaunga5575
    @simbarashemaunga5575 Год назад

    Good content. However, as always you re too fast, it literally feels like you are flexing instead of actually teaching or enlightening someone.