【问题标题】:Stancl/Tenancy - How do i automatically run the migrations when a new tenant is created?Stancl/Tenancy - 创建新租户时如何自动运行迁移?
【发布时间】:2021-09-18 06:17:32
【问题描述】:

当我创建新租户时,新租户的迁移不会运行,我想知道如何在新创建的租户创建后自动运行迁移。是否有必须在后台运行的工匠命令才能工作?到目前为止,当创建租户的请求通过时,这是我的控制器代码。

public function store(Request $request)
    {
        $this->validate($request, [
            'company' => 'required',
            'domain' => 'required|unique:domains',
            'name' => 'required',
            'email' => 'required|unique:users,email',
            'password' => 'required|confirm'
        ]);
        $tenant_id = '-' . Str::slug($request->company, '-');
        $domain = $request->domain . '.' . 'saas.test';

        $tenant = Tenant::create([
            'id' => $tenant_id
        ]);


        $tenant->createDomain([
            'domain' => $domain
        ]);

        $tenant->run(function()
        {
            User::create([
                'name' => $request->name,
                'email' => $request->email,
                'password' => bcrypt($request->password)
            ]);
        });

        tenancy()->initialize($tenant);

        return redirect($domain);
    }

【问题讨论】:

    标签: php laravel multi-tenant


    【解决方案1】:

    尝试在你的控制器方法中运行 artisan 命令:Artisan::call(‘tenants:migrate’);

    【讨论】:

    • 什么都不做。
    • 我让它工作了,我刚刚做了 Artisan::call('tenants:migrate')
    • 我的错。下次我会更专注于答案
    猜你喜欢
    • 1970-01-01
    • 2021-02-24
    • 2022-01-26
    • 2019-02-25
    • 2016-08-29
    • 2019-10-30
    • 2022-07-13
    • 1970-01-01
    • 2016-07-28
    相关资源
    最近更新 更多