Return to homepage

Comments

Peter Ajakaiye

Hi Alex, thanx for the great tutorial, but will like to know how can I implement Domain Tenant Resolver so that I can switch between each tenant by using e.g. tenant1.localhost, tenant2.localhost and localhost will represent the main app.

  • 0
Raphael

Hi Alex,

When I use parent::boot in the ForTenants traits it gives the error below,

Symfony\Component\ErrorHandler\Error\FatalError Cannot use "parent" when current class scope has no parent

How do I resolve it

  • 0
gustavo

Just remove it.

In most recent Laravel versions you don't need that and don't need to implement basic scope either

  • 0
Shoaib

I am trying to integrate the laravel-backpack admin panel with this. Will you please give me an idea about this?

  • 0
Lim

Hi Alex,

When we use "public static function boot()" inside trait "ForTenant.php". How can we modify/add more data to "public static function boot()" ? Like my case I need to add

static::creating(function ($order) { $order->status = self::REQUESTED; });

to "public static function boot" too.

  • 0
Christiaan

Hi Alex, when setting this trait on a model that is used within queue jobs I am getting this error: Argument 1 passed to Qwans\App\Tenant\Scopes\TenantScope::__construct() must be an instance of Illuminate\Database\Eloquent\Model, null given, called in C:\laragon\www\qwans\app\App\Tenant\Traits\ForTenants.php on line 24

Any thoughts about this? I kinda like solved by adding this before the parent boot in the ForTenantTrait if (app()->runningInConsole()) { return; }

Hope you could provide a better solution maybe?

  • 2
Rudolph

I am facing this same issue. Don't know how to resolve it.

  • 0
Renwar

3rd Video: why using "belongsToMany(Company::class)" in the users Model? Why not using Users HasMany(Company:class)?

  • 1
gustavo

Because it's a n to m relationship

  • 0
Nathan

I'm unclear as to how you'd assign a user to a tenant? I imagine there would be some kind of invite method on the suer model?

  • 2
Renwar

Same question here!

  • 0
Nathan

Where is the foreign key defined in this? It wasn't in the migration when creating the table was it?

  • 1
Renwar

I think the foreign key is automatically assigned with the table company_user in the video #3

  • 0
Josip

Hey Alex, how would you disable scope on a model for some cases, like when using Laravel Scout?

  • 0
Mmadi

Hey Alex,

Great course but can you explain how we can add a subdomain for each tennant like : tenantx.mydomain.com tenanty.mydomain.com .... I hope, you could explain me how to do it soon as possible Thanks you.

  • 1
Alex

Sure thing! I was actually going to do a slight variation on this course and use the https://laravel-tenancy.com package. This makes it super easy to sort stuff like domains out.

What do you think?

  • 0
Mmadi

it’s will be a good idea to made an course for Laravel Tenancy package. I think it’s a good package.

  • 0
Alex

Great, thanks.

  • 0
Zubair

@Alex, do we have any chance of course on this package ??

  • 0
Gheorghe

Hello, I have this question and I will appreciate any help (thank you)

  1. How can I define a default company for a user, when he login into the system, the default company to be active and after that he can choose other compnies which belongs to. (I hope I was clear enough :)).
  • 1
Nagarajan

you can check if $request->company and session()->get('tenant') are empty in Tenat Middleware if they are you can set the default company there

this is the code which i have used to set the default company

1if (!empty($request->company)) {
2 $tenant_id = $request->company;
3} elseif (!empty(session()->get('tenant'))) {
4 $tenant_id = session()->get('tenant');
5} else {
6 $tenant_id = auth()->user()->companies[0]->id;
7}
8
9$tenant = $this->resolveTenant($tenant_id);
  • 0
kabelo

Hi

Does anyone have an idea of dealing with what I call System models, i.e. models that belongToMany tenants? As a workaround, I'm actually passing the tenant along with the related belongsToMany models and then dealing with it like that. I feel like this is incorrect though.

If it isn't, I then wonder why we need the scope instead of passing the tenant along and working from those relationships.

  • 0
hi

great but leran how to add a domain for eche company

  • 0
Ash

This is a great course but my only issue is the use of session for storing the current tenant. The reason for this is that you can't have different tenants open in different tabs. Use of the session also limits the ability to create a REST or stateless api. I don't think there is a way around this and the tenant ID in the needed in the url always - basecamp api does this with account id - https://github.com/basecamp/bc3-api.

Other than that the rest of the course is awesome and has helped with a current project.

My only question is with the notes above, is the only way to achieve the session-less solution is to remove the session call in the middleware and to include the tenant id in all of the routes and controller actions?

  • 0
Steve

Hey Ash,

If you want this to be used for a stateless API, and still follow the same principles, perhaps look at utilising Redis Cache over sessions? That is the best way I can think of, unless you want to push this over to a custom Header variable instead. It all depends on use case.

  • 0
Josué

Why would you want different tenants open in different tabs? You can always open an incognito window.

  • 0