Stancl/Tenancy – How do i automatically run the migrations when a new tenant is created?

When i create a new tenant the migrations for the new tenant doesnt run and I was wondering how I would automatically run the migrations for the newly created tenant after it is created. Is there an artisan command that has to be run in the background for it to work? Here is my controllers code so far when a request comes through to create a tenant.

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);
    }

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try to run artisan command in your controller method: Artisan::call(‘tenants:migrate’);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x