Now, let's take care of the situation of multiple tenants per user.
We have the database structure already, with tenant_user pivot table. Now, the question is where to save the active current tenant.
Saving Current Tenant
Two choices that I would suggest:
- A boolean column
is_activein the pivot. - Saving current tenant ID in the
userstable.
In this lesson, we will use the second method and add the current_tenant_id column to the users table.
First, the migration.
php artisan make:migration "add current tenant id to users table"
database/migrations/xxx_add_current_tenant_id_to_users_table.php:
Schema::table('users', function (Blueprint $table) { $table->foreignId('current_tenant_id')->nullable()->constrained('tenants');});
app/Models/User.php:
class User extends Authenticatable{ protected $fillable = [ 'name', 'email', 'password', 'current_tenant_id', ]; // ...}
Let's refresh the database so we can make sure that everything works.
php artisan migrate:fresh
Then, we need to set the active tenant when a user...
hi, i am new to laravel and vue3 and have been following your program, so foar its been helpfull.
i a building a app with seperate front end and backend, so my app is essentailly based on apis, now i am stck i need to understand how do i add global scopes created in laravel into vue 3 front end
any help would be much appreciated
regards rahul
further my use case here is to crete workspace and all the back end resoureces to be restricted by the workspace,
need 1: alll user are in default workspace and only few have ability to create and work on a new workspace. need 2:all files and foleder in a work space are restricted to the users with ability to view/moderate the workspace
i have followed ur instructions and have a api to manager/moderate workspace but i need all models to be restricted by the workspace, only issue is reactivity at the fronend with vue
in this example you have scope defiend on the blade with works like a charm but i have not been able to replicate in vue front end which is completely separate.
Please help
Well, in theory it should work like this:
From your separate front-end, you ask the API with the user credentials, and then by that user you get the data only for that user.
So it doesn't change on the back-end, it's still the same global scope. The problem is probably how you authenticate user from the front-end.