WARNING---
There is a security problem when saving the password in plain text in the data field of the tenant table.
Hay un problema de seguridad al guardar la contraseña en texto plano en el campo data de la tabla tenant.
How to validate that the email is unique in the tenant's table?
Hay, I just crated my fresh laravel application called sms.test, but i type sms.test in the browser I get 'Hmmm… can't reach this page' errro message. How can I fix this
Hi Alex, may I download the source code this project for documentation?
Apparently, multitenancy with subdomain + DB for each tenant is the way to go. I have some questions:
Thanks!
You can extract features into packages/modules that can be enabled/disabled as per need or based on subscription level.
Hi, great course! I have a few questions:
How would you go about allowing tenants to login from the central domain? When they enter their email and password it automatically logs them in and redirects to their domain dashboard?
Also, how can an admin area be created to allow admins to create tenants? Would you use a different db table? Or add an 'isAdmin' column on the users table?
Any reason you chose stancl/tenancy over spatie/laravel-multitenancy?
Also, do you plan to show how to use a single database for tenants?
If you are using VSCode, you can click CTRL + ALT + A to add all Controllers.
what i did is set central_domains like this:
1'central_domains' => config('APP_URL')
so i can just use the .env config data
Hi Alex
I am using window xampp. and create virtual host "saas.test" for demo integration.
When i run
http://bar.saas.test/
It's give me following error
"Hmm. We’re having trouble finding that site."
Is their i missing something in virtual host?
You need to create a virtual host for the subdomain also.
Follow these steps : Virtual host redirects a particular domain to a specific application file directory in the server. Step 1: Go to C:\xampp\apache\conf\extra and open httpd-vhosts.conf file. Step 2: Add virtual host configuration for particular URL at the end of file.
<VirtualHost *:80> ServerName mylocalapp.test // URl to set ServerAlias mylocalapp.local // Another URl to open same Web App DocumentRoot C:/xampp/htdocs/mylocalapp // Application file directory (folder) in XAMPP localhost </VirtualHost> You can add multiple alias names (domain name) by separating with space or can add another ServerAlias line in the new line.
Step 3: Save and close. Now, your custom domain for local applications is ready.
Greetings Alex, for some reason the sub-domain does not work for me I just registered it (codersfree.multitenancy.test) and does not want to access but when I use the central domain if it works, could you give me a possible solution? Thanks in advance
Your OS is Windows and Macintosh
Im using laragon, cant manage to get the subdomains to work. Has anyone had the same problem ? any solution to this?
Manually adding the subdomain into the hosts file works just fine.
Any method for automatization of this?
It is possible that you can show how to make all tenants can navigate from the same path, ie.
Tenant 1 if it is a paying tenant has its own subdomain free account: tenancy.test/profile paid account: app1.tenancy.test/profile
While tenant 2 and 3 are free accounts so they have no subdomain.
Why and when we need multi tenancy?
When you sell the same application to different companies, then you sell them the basic functionality of the application (generic) instead of duplicating by hand project by project that has the same code but in different databases where you will never access another customer's database.
When you build SaaS applications is a good example. You want the same application, but different databases for each client. That makes things easier.
In case this helps someone else out, if you're using Laravel Sail use the root
user, not the sail
user in your database connection as it doesn't have create database access (MySQL/MariaDB).
Fantastic course Alex! Any plans to extend the course with Cashier for tenant subscriptions / payments?
Alex, thank for this brilliant course) It’s very simple and so amazing) Can you tell me please, how can I login from the central application and the redirect to the user’s subdomain dashboard?
Hi there! I'm following this course step by step. Looks good! The first Tinker tenante create([]) I get the following error:
$tenant = App\Models\Tenant::create([]) Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (SQL: insert into
tenants
(updated_at
,created_at
) values ...
Any idea why it should have a default value? And how to fix this issue?
Thanks!
Here are a few solutions.. maybe one of them will work for you?
https://stackoverflow.com/questions/25865104/field-id-doesnt-have-a-default-value
Chapter 10 @ 2:08
Inside the CreateTenantAdmin Job constructor:
1public function (public Tenant $tenant)
I can't move past this error. Any insights? Thank you.
same error, do you know the solution for this issue?
Were you able to fix it?
Although my visual studio detects it as an error, but it runs properly in browser. I just ignore the error.
Constructor property promotion is only in php8. You might be on php8 but your composer file might have something like php 7.3|8.0 etc. Your IDE would then "think" you are on 7.3 although it's not the case. So, your code will still work.
In the constructor pass the data
public function __construct(Tenant $tenant) { $this->tenant=$tenant; }
Thank you very much, solved the problem
Thank you very much, work for me
Hi :) Thank you so much for this tutorial. Please note that for a beginner who is just "following along" the auto import done at around 30seconds on the 5th video "Creating Test Tenants" took awhile to figure out. I only realized because your line numbers on the left changed. Would be good if you could mention this.
For those who want to implement the MustVerifyEmail
:
1class User extends Authenticatable implements MustVerifyEmail2{3...4public function sendEmailVerificationNotification()5 {6 $this->notify(new CustomVerifyEmail);7 }8}
1class CustomVerifyEmail extends VerifyEmail 2{ 3protected function verificationUrl($notifiable) 4 { 5 if (static::$createUrlCallback) { 6 return call_user_func(static::$createUrlCallback, $notifiable); 7 } 8 return URL::temporarySignedRoute( 9 'tenant.verification.verify',10 Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),11 [12 'id' => $notifiable->getKey(),13 'hash' => sha1($notifiable->getEmailForVerification()),14 ]15 );16 }17}
1class Kernel extends HttpKernel2{3...4protected $routeMiddleware = [5 ...6 'verified' => CustomEnsureEmailIsVerified::class,7 ];8}
1class CustomEnsureEmailIsVerified extends EnsureEmailIsVerified 2{ 3public function handle($request, Closure $next, $redirectToRoute = null) 4 { 5 if (! $request->user() || 6 ($request->user() instanceof MustVerifyEmail && 7 ! $request->user()->hasVerifiedEmail())) { 8 return $request->expectsJson() 9 ? abort(403, 'Your email address is not verified.')10 : Redirect::guest(URL::route($redirectToRoute ?: 'tenant.verification.notice'));11 }12 return $next($request);13 }14}
Hi) Can you help me please with login from central and redirect to user's subdomain?
Hello Dear Alex, Kindly cover the global user authentication in this course, That will very important and will be very helpful for everyone I'm sure.
Yes. We need this
Run migration in central db before moving the users migration folder to the /tenant folder
Hi Alex
I've noticed the last couple of series didn't have the download link for the videos. Is that a policy decision or just that the appropriate checkbox wasn't clicked? I find it useful to be able to download videos to review them at my leisure (in VLC player, or similar) rather than have to review them in a browser.
Iain
EDIT: Video download links are available now - thank you.
Dear Alex, This is a very useful tutorial, we appreciate you very much. But I have a question, what if I want to merge subscription/saas with this project. My specific question is, you have saved the tenant creator or user data into the tenant sub-database users table, but if I want to make a subscription of that user then I need that user or how can I do that? or what should I do here?. Can you just give me a hint? Should I make the subscription on the tenents table instead or the users table or is there any better approch?
For some reason, I getting 404 error on "/" even after I added domain() on RouteSeviceProvider.php
. I am only having problem on "/", other routes works fine.
Hello i use valet after creation of tenant and domain using "php artisan tinker" the subdomain redirect me always to "/" homepage route (welcome view). i think the valet subdomain has priority or something like this.. help pls
You have to modify your RouteServiceProvider.php
and add domain on web route.
Alex, you're the man, you have no idea how long I've been waiting for something like this I've spent countless hours searching the web for It thank you sir
Can you explain how to handle tenancyforlaravel with jetstream and teams ?