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
Just remove it.
In most recent Laravel versions you don't need that and don't need to implement basic scope either
I am trying to integrate the laravel-backpack admin panel with this. Will you please give me an idea about this?
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.
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?
I am facing this same issue. Don't know how to resolve it.
3rd Video: why using "belongsToMany(Company::class)" in the users Model? Why not using Users HasMany(Company:class)?
Because it's a n to m relationship
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?
Same question here!
Where is the foreign key defined in this? It wasn't in the migration when creating the table was it?
I think the foreign key is automatically assigned with the table company_user in the video #3
Hey Alex, how would you disable scope on a model for some cases, like when using Laravel Scout?
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.
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?
it’s will be a good idea to made an course for Laravel Tenancy package. I think it’s a good package.
Great, thanks.
@Alex, do we have any chance of course on this package ??
Hello, I have this question and I will appreciate any help (thank you)
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}89$tenant = $this->resolveTenant($tenant_id);
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.
great but leran how to add a domain for eche company
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?
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.
Why would you want different tenants open in different tabs? You can always open an incognito window.
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.