Return to homepage

Comments

Christos

Apparently, multitenancy with subdomain + DB for each tenant is the way to go. I have some questions:

  1. How do we move forward after what Alex showed? Do we just continue building our SaaS as we would normally do for a non-multitenant project? Any pitfalls?
  2. How do we handle situations where a tenant (actually a customer) needs extra functionality that the other customers do not? I mean, the code in the controllers/views is currently identical for every tenant. Is there a way to introduce more features for specific tenant(s)?
  3. Do 3rd party packages work with multitenancy? Or are there any limitations?
  4. @Alex: Any plans to add more episodes in these series? If yes, what will you cover?

Thanks!

  • 1
Wilfred

You can extract features into packages/modules that can be enabled/disabled as per need or based on subscription level.

  • 0
Keith

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?

  • 0
Keith

Any reason you chose stancl/tenancy over spatie/laravel-multitenancy?

Also, do you plan to show how to use a single database for tenants?

  • 2
Muhamad Sulaiman

If you are using VSCode, you can click CTRL + ALT + A to add all Controllers.

  • 0
Exploit

what i did is set central_domains like this:

1'central_domains' => config('APP_URL')

so i can just use the .env config data

  • 2
anuj

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?

  • 0
Keith

You need to create a virtual host for the subdomain also.

  • 0
Raymon

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

  • 0
petar

Im using laragon, cant manage to get the subdomains to work. Has anyone had the same problem ? any solution to this?

  • 0
petar

Manually adding the subdomain into the hosts file works just fine.

Any method for automatization of this?

  • 0
Alexis

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.

  • 0
Abrar

Why and when we need multi tenancy?

  • 0
Alexis

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.

  • 0
Denis

When you build SaaS applications is a good example. You want the same application, but different databases for each client. That makes things easier.

  • 0
Alexander

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

  • 1
Alexander

Fantastic course Alex! Any plans to extend the course with Cashier for tenant subscriptions / payments?

  • 2
Vlad

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?

  • 1
Henk-Reijer

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!

  • 0
Billie

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

  • 0
Billie

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.

  • 1
Muh

same error, do you know the solution for this issue?

  • 0
Alexis

Were you able to fix it?

  • 0
Muh

Although my visual studio detects it as an error, but it runs properly in browser. I just ignore the error.

  • 0
Shawn

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.

  • 0
petar

In the constructor pass the data

public function __construct(Tenant $tenant) { $this->tenant=$tenant; }

  • 0
miguel

Thank you very much, solved the problem

  • 0
Nikki

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.

  • 1
Pavel

For those who want to implement the MustVerifyEmail:

1class User extends Authenticatable implements MustVerifyEmail
2{
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 HttpKernel
2{
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}
  • 0
Vlad

Hi) Can you help me please with login from central and redirect to user's subdomain?

  • 0
Rid

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.

  • 6
Fatih Mehmet

Yes. We need this

  • 0
shingi

Run migration in central db before moving the users migration folder to the /tenant folder

  • 0
iain

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.

  • 2
Rid

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?

  • 4
Shoaib

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.

  • 1
Azerdaoui

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

  • 0
Shoaib

You have to modify your RouteServiceProvider.php and add domain on web route.

  • 0
Jovani

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

  • 7