Making Multi-Tenancy with JetStream

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so i am live i think let's start this and uh first please tell me if sound is good video quality is good if you are facing any issue then please tell me okay let's start and first i am going to check okay is everything right so we have this browser let's move it to another window and let's do something here i can open this on okay let's do okay so finally we are here and now let's start so people are saying okay so let's start and what we are going to do today we are actually going to use the multi-tenancy package from spasi and this is the package and i can go here this package we are going to use and also we are going to set up this uh jet stream and see how we can use this jet stream just for the tin end not for the central app okay so first what is multi-tenancy so think about multi-tenancy is like having a simple level application but according to the sub domain we are visiting or the user visits we are going to change the database connection this space is level multi tenancy this multi-tenancy package from tenancy for laravel is really awesome but it has more than the use of the configurations here we have so let's see your questions okay so nothing is there okay now let's start with level 8 simple so level new multi tenancy simple so okay so let's wait so i'm using composer 2.0 which is obviously not yet released but i'm trying it and i can easily say it is very very fast you cannot see the speed because my macbook is heating up and i'm running obs with my mobile data because electricity issue is there so that's why and then we are going to set up everything okay once it is done then we are going to open it with vs code and then we will install the multi-tenancy so i think it is already completed yeah that's done so it's very easy let's open multi-tenancy with the vs code okay so that's not a big deal i can easily check here done so here we are and if i open terminal i can check for everything is working fine or not yes i think it is working on localhost 8000 okay that's nice let's zoom it for you like this one and obviously if i go to the foo dot localhost uh localhost to 8000 it is there or if i check for test.localhost dot 000 it is working so these things we need to check how we are going to do things here and let's see what we have on the web dot php we have this nothing else cool so what do you think about multilingually please tell me put the base installation here and yeah it is taking time no not taking time so let's copy this and paste it so yeah it is done and you can see the composer 2.0 is very very fast just in a few seconds it's done with the downloading very very nice thing so once i have done that what i'm going to do i have just initialized git and i will say just installed the package why i have done that so that i can show you that what are changes made by this package so after this we need to publish this details for this package and for now it has just given this multi-tenancy.php file so multi-tenancy dot php which is inside the config file i think yeah here we are you can see that's why i did this git because now i can easily see which file is modified and the file you can see is here so this file is very very nice and very very useful file it's a configuration we are going to spend a lot of time here also next they have given this configuration file then we have to use these two middlewares so first it has given that you can use this inside your web if you want all of your application to be to be tenant aware but i think we can do a better thing which is also given here it says if you want you can create this tenant kind of middleware group and where we can do that obviously inside our app http kernel and here we can see we have this middleware groups we have this web then api and after that i can simply paste it that's done so whenever we want we can simply use tin end as the middleware so that it will be aware of the teenage so these two middlewares are one is needs tenants that means it required the tenant that also mean that we should be on the we are we should be on the you can say sub domain to be able to use this package and then it says ensure valid tenant session so tenant session should be there okay so after that we can simply jump to multi uh use multiple database now multiple database means for every tenant for every subdomain you can say we are going to create a new database okay that's done so let's now see if landlord and before that we need to go to the configuration of multi-tenancy which is this one this file i told you and here we need to set the tenant database connection also landlord database connection so if i go here you can see tn database connection if i'm not giving anything it will take the default connection but we must provide the landlord one so land lord oops landlord this one if you have any question let's uh need multitenancy without jet stream it's okay so we will try that once again come back here next that in database this is done and then let's create these two databases so first we need to go into this configuration and we have a database and here you can see the default one is mysql we can convert it into tnent or you can directly convert this from your env file so you can see that db connection which is given here we can define that the default world one is thin end okay then we can go here and here we have a mysql connection and i'm going to copy all of these things and paste it like this so now we have a two mysql connections so one i call tenent and the second i called landlord for the landlord we are going to use the one we define here so here we have a multi-tenancy and i can just call it tenancy because i have created the database called tenancy and on this tenant the tenant database is not hard coded it will be dynamic according to the tenant visiting our website so we need to provide it as a null which is given here so you can see database null and landlord is the simple one then we need to migrate the landlord database but if you go on this database and migration you can see we are having these user and password reset and failed job these we require for the tenant not for the landlord the central app you can say now it says we need to get the migrations so open the terminal and here paste this one and now you can see it has actually created a directory called landlord inside that we have a simple migration called tin end and this one we need to migrate but if i run php artisan migrate this will going to run the migration inside the migrations table not inside the landlord table for that we need to copy this command which is actually going to change the path and this time you can see we are defining the path as a database migration and landlord and the database connection should be the landlord one and we know the database connection for landlord is the one we have provided on dot env file which is this one tenancy now here i can see if i can show you now we have two databases one is this one let's open the tenant one okay so we have this tenancy which is empty no table are there if i run it we just have one table called tenant and if i refresh teenage table is here okay now here inside this tenant table we can see we have structure name domain database these three things are there so let's register one by one so name is let's say sarthak okay or i can simply say shop not sartha then shop.localhost and database is let's say shop so these are the things and let's save this and that's given here so you can create your own database now if i try to visit shop.localhost 8000 it's giving the base home page because it doesn't check for any you can say sub domain so we need to make sure we are [Music] getting aware of the tnt so we need to give this task this file on the switch tenant task on the multi-tenancy so here we have a multi-tenancy and somewhere we can find yeah switch t9 task paste this one and after that you can see it says create database we have created the database so let's create a database for shop so i can close this one create a new database called shop and open it obviously this database doesn't have any tables so now we are going to migrate for tnt now whenever i say migrate for tenant this artisan tenant artisan command we have so if i search here on the php artisan you can see we have one tenant artisan command so these commands will going to run for let's say admin so admin dot local host and database is admin okay so okay so primary q2 and create one more database called admin okay so it's not opening hi but it is created so i can close this tenancy and then i can open this admin one okay so we have now two tenant database which are empty now if i run this command this is going to run for two times because we now have a two tenant and you can see one is it is running command 14 in shop and running command 49 admin it's just a name given i have in mind okay so this means now both of these tables are here and doesn't have any user obviously so how we can check and how we can verify that we are having that tenant working so everything is there and if i can see it's given working with the current end how we can determine that which tenant is available for that we need to go to the automatic determining the current tenant and here we need to give this class which is actually going to find the tenant for us and here it's given null but we can provide it like this and then whenever i want to have the tenant detail i can say app current tenant so let's show this one here on the welcome page so i can go to the welcome dot blade dot view and just to search for document and here we are and above the document i can create a p tag and inside this p tag i can actually give the class name and not class let's give this style as color white let's refresh and now you can see it says shop and let me zoom this for you now i can also say give me the name only yeah so now we have a shop here if i can convert this to h1 tag yeah so now we have a shop and if i say admin dot local host to colon 8000 then you can see it says admin but then if i only search for only go to the central app the landlord app it's giving error okay so how we can solve this one let's see is there any question no question from anyone no issues let's once again get back and let's solve this issue and to solve this issue it's actually saying current tenant it's required continent okay so how we can solve it and we can go to the web.php file and we are serving this for every tenant plus the landlord but you know this level provide a very nice function to search for the domain if domain is shop dot localhost okay then create a group inside that group i'm going to give this but also i'm going to define middleware and middleware we know we have created tenant okay so this time once again we are having this tenant otherwise we are having this one let's try on instead of returning this i can return shop let's try still we have the same thing admin is there shop is having shop okay so now we can make it dynamic and i can say tenent and i can actually return the tin end which i can get from here so shop and admin is admin you can see admin and you can see shop but now it's still asking for this thing what i can do i can actually move it up okay so this is not the thing how we can solve this one any suggestion okay hmm so central one is not having any domain so if there is a okay okay i can do one thing i can define domain here also and this is the local host only no sub domain and let's try if i can move it up and still asking for the same thing um do the same localhost domain and obviously this should be a group okay group and inside this group let's create a route still the same shop admin antennae what if i say phperson route clear and then restart server okay i got the point i got the point here we are having this and what i need to do i need to check if there is any tenant that means we how we can check there is tenant or not so if i go to the working with tenant on the documentation yeah here we can see we have a check current check so if there is any tenant then it will give true otherwise false so this one required and it is actually this exact path okay if there is any tenant then only show these things otherwise not okay now it will surely going to work so when login then change database and dynamically change the database yes we are going to do that we are dynamically going to change the database so shop add-in and we are back with the home page okay so here we are so this means we can simply return the view welcome view here also on the landlord route oh sorry on the tenant route and everywhere when we are having on the tenant then we are having the welcome page with the tenant name otherwise we don't have any tenant name so this is how you can use the uh also with the views but now let's re start with the jet stream and install it so that we can really see that it is having a different different database and it's connecting and talking with a different database at the different for different users so let's install jet stream so i'm going to say first acm and set up for multi-tenancy packages done and now let's install this composer required laravel jet stream and once again i'm using composer 2.0 which is very fast you can see done even though laptop is heated up and internet connection is very slow next we need to use this live wire i'm using live wear because it is quick uh i i will also going to show you how you can use the inertia so livewire is going to set up everything all the components of live wire and let's see how we can tackle this so finally we need to run this one and now it will take some time npm is not so fast then composer and i can close everything else because now we don't need anything okay so this is uh running and let's see if you are having any question my doubt is when user log and user exist or not if exist after that person database connect okay ravi you will see everything here and i'm going to show you how you can register how you can log in and do every sort of thing with this jet stream using multi-tenancy and for every uh you can say every user we are going to have a different different user i can say for every tenant we are going to have a different user database that's the goal here so this is how we can actually create a multi-tenancy looks like it is a very difficult task but in reality it is not so difficult we are getting this error we will going to solve this one don't worry about that so we are getting that error everywhere and let's solve that thing so this is having related to the sessions required in a jet stream but i'm going to limit that i'm not going to have the sessions for the jet stream so what i will do i will go to the env file and session driver is a database i will just convert it to file so that i will have a session database as a file not session driver as a file not database okay so if i now refresh we will not get this error yeah you can see we are not getting error still we are getting the home page okay so this is i think installed and you can see everywhere yeah we have this login register here also if i zoom in login register and log in and register but now what i want i want to go to the login page let's see if i click on login yeah i can easily go to the login page and if i go here on the login for the shop yeah i can go for the admin i can go for the login for this landlord i don't want the user to visit or landlord to visit this login i want to restrict the jet stream only for the tenant okay for that what i can do i can open the tenancy not tenancy the jet stream configuration inside the config directory and here although it's not given but we can provide middleware here and we can provide web middleware plus we can provide tenant middleware okay so by doing that by doing by providing this tenant middleware this means if i now go to the landlord the base url only localhost 8000 slash login it will going to give some error which is not giving because we need to do one more thing we actually need to do on the 45 and yeah on the 45 also we can provide the tenant as the middleware refresh this and now it says the request expect a current tenant but none was set so now you can see it is only available for the tenant not for this you can say landlord so we have restricted that thing now since uh landlord can not visit the jet stream routes but tenant can visit you can see i'm refreshing and that's fine now let's go to register and try to register i'm going to register here password as the password click on register and you can see i am easily able to redirect to this dashboard and see the dashboard is for the shop.localhost colon8000 slash dashboard once again but here i am on the admin side see if i try to log in with the email and the password i have created on the shop side it will say a credential does not match because it is switching the database connection dynamically okay so let's see can you explain further i'm late uh so you can actually watch this stream later because um currently i have done lots of thing and it's not good to explain everything let's uh so successor i installed that stream after watching your stream my problem is while registering user will get the different role but you can't find the register route in the web and api actually register route is not available on the web you need to check on the package actually okay let's let's move move so since we can see uh on the shop side i am logged in and on the admin tenant i am if i'm trying to log in with the detail i have created or the user id i have created for the shop site i cannot do that so since we have this let's go to the profile and see if we can easily change this name or not so if i say any yes click on save refresh this page and absolutely fine everything is working fine let's register here with us with some other name and go and register this time i can say bitfumes so bitfinsite gmail.com password is pass word once again password okay yeah i can easily log in and the profile is there yes very nice so on the shop side you can see we are on the shop try to change the photo go to the photos image okay so it can be available here if i save it yes no it says profile path okay so what happened here let's see on the database on the migration [Music] we have this user table in this user table the jet stream has added one column called text field for profile path photo path and jet stream has added this one before installing jet stream we have actually migrated everything for every user now if i try to migrate for tin end it's running for two-factor authentication personal access token and first session but not for the user okay so that's the issue we are having here so if you can see on the user we don't have the photo path what we can do because we are on the development phase so we can simply say fresh and remember to define the fresh here because whatever we define here is actually going to run for every tenant okay so yeah it's done and now if i refresh here now you can see we have a profile photo path available that means we lost all the users for every tenant we can simply register once again so password password and i'm registered and i can easily login so oops look at okay once again try to visit profile and this time if i select a new photo save it okay so it is saved but now it's not showing here so it says valet first i don't need valet so i will change the dot env app you are a local host 8 000 and it's recognized that's good refresh and still we are not having this hmm how comes how we can solve it okay so hardik is there and hardik is the follower thank you hardik and sanjeev if no sub domain it has to take to the faulty end you're right so if there is no tenant no dot localhost colon 8000 now it says the request has a current tenant but was not set it's not finding the thin end now how you can actually solve this problem remember on the is that multi-tenancy configuration we have this tenant finder and this tenant finder is the file responsible for getting the tenant and here you can see we are having this you can raise exception from here and then handle that exception anywhere you can redirect it to somewhere else you can do these sort of things so that's how it is given here okay let's solve our image problem so image problem is because of this it is finding storage profile photo everything is fine i can see [Music] on the storage app public profile photo we have photos starting with vb and this one is there it is available okay so what's the issue is it we need to add php artisan storage link okay it's working cool yes we we have done with that now let's try to remove it's the image is removed try to add new photo add it new photo is added that's good okay let's try to change the password with this password to secret one two three this time and this is it done i think okay so let me try these things okay once again try to log in and this time if i try to log in with the old password it's not logging in i can easily log in with the new password okay so that's how we can actually use everything and you can define everything is working on absolutely fine two-factor authentication is also working you can see these things are there and this is how we can use the multi-tenancy app for our [Music] with the jet stream so it was very short video or it's not video just a live stream and i'm going to add these things into the in-depth level course for as update for level 8 and that will be a proper you can say course which is a proper project not a course proper project going to be uh with the multi-tenancy and let's see what i will come up with these things and that will be for the update of in-depth level and if you visit in-depth level dot com you can find that i have added one simple line which is update for level 8 is coming and keep in mind that after update uh after the update of this level 8 for this in-depth level course the price is going to be increased so if you have not purchased it you can go and have this one before the price increases so that's how what i can do and oh i got no time now i will watch this later thanks arthur okay that's good can you please tell me what is cmd name it autocomplete and looks nice oh i think you are asking for this command uh the terminal look so this is the uh what's the z shell so z shell uh rc no no oh my god this is oh my g shell oh my z shell okay and there is a theme i have installed here which is i need to check for that theme and the theme name team name theme name not agnostic i forgot the name i think it's velocity or which one is this i really forgot the name i will actually post this in the comment section for this one and i need to find it i don't know what's the theme it's a velocity 10 i think oh nuno is here oh wow no no thanks for your visit to this live that's very nice so guys nuno maduro is here and i don't know if he is live or not but it's very nice to have someone from the laravel community and someone from the core laravel team and nuno is the now a core team member of laravel so very nice nice to see you brother okay so tanzan says sir will your react course have a level of back end on the project no it's just a simple react it was just 100 react that's it power level 10k yes this one is the theme name power level uh 10k uh who asked for this one i i don't know yeah thanks uh hardy this is the name if you want you can install it with the z shell it's for the z shell so this was the live stream i did and i will going to try these kind of live streams again and again tell me how you think about this live stream should i do more or less or any tips to increase these things every comment is valuable for me so let's do something else later and this is till this level i think it's done because we have used multitenancy with the jet stream and one more thing is there yeah you can use this package this tenancy for level this package i said extremely good this multi dnc by sparsi is very very basic it just do two things it just have the middleware and it just switch the tenant done but this package does lots of the hell lots of things like it do it it has a middleware it just switches the task it just uh set the routes for everything and you can really do anything you want for this it's for event listener scope session horizon nova package no passport telescope liver everything is included in this tendency for level package so that's why it is very very very very nice but since it is very very very very nice it's difficult to set up and difficult to manage but as i said this package from espacie is very very minimal it's just allowing the switching the switching of the database and which is very very nice thing because now it's up to you how you want to create your tenancy and how you want to manage the tenancy the basic difference between these two package is the approach they have so espacie's approach is to have the central database in a different database file called landlord and just the opposite is done by this package this package is actually having the central like you can say landlord as a main migrations and instead of landlord they have a tenant like tenant kind of directory and where they have all the tenant related migration so you need to move all the migration into the tenant directory which is a task a headache for you because every time you use any external package you need to install it you need to move every migration to there and then you need to run that it's difficult so i feel this one this approach is very very easy but now it's up to you which one you want to have okay so i think now it's time to go and we have some can we have some videos on laravel ecommerce and laravel cms like october uh i don't think so i will do for video for cms like october because i feel like using cms is not my task but yes i have will try to use the e-commerce and whatever will be the scenario i will obviously share it on twitter or on the youtube post which one is best suited for scaling in my opinion for scaling for a very high large project tendency for level is very very nice if you are not very pro in level but if you understand level from its core go with the sparsi package both package can be used to create high level even a sas sas project you can do anything with any package but as i said this is party package you need to understand the level from the core level for a tendency for laravel you need to read the documentation again and again and again and again that's the simple thing actually ravi the thing is this package the task of these packages is simply to change the database they are changing the database we don't have to do anything okay developing okay okay i got your point i will try i will try that thing sure okay so i think still i'm getting questions bro i'm having problem deploying level with the lamp stack please this is just uh instead of manual deploying try to use cloud ways or forge or various other platform which can be useful for you one last time i'm saying that i'm going to say you goodbye we will meet in some other live stream also make sure you will come on the sunday live for a regular sunday live at 11 o'clock according to indian standard time so bye bye and we will meet tomorrow not tomorrow on the sunday okay bye
Info
Channel: Bitfumes
Views: 11,390
Rating: undefined out of 5
Keywords:
Id: uvnvYzQ2fw0
Channel Id: undefined
Length: 48min 10sec (2890 seconds)
Published: Thu Sep 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.