GithubHelp home page GithubHelp logo

Comments (38)

juanparati avatar juanparati commented on June 27, 2024 5

@wahyubaskara: try to change:

"default" => "mysql"

by

"default" => "tenant"

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024 1

@Saimon-git, have you followed the documentation?

from laravel-multitenancy.

refaatgamal avatar refaatgamal commented on June 27, 2024 1

Already working as docs but landlord didn't work how can I login as landlord I make virtual domains in local host for tenants but when I go to project direct with out tenant domain it gives me no database selected issue

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024 1

The open-source package philosophy lies in free cooperation: if you are here to search for an urgent solution, the best way is to dig inside the code to find it yourself.

Anyway, please create a public GitHub repository with your code to help me to understand where your errors are.

Thanks.

from laravel-multitenancy.

martincarvalho avatar martincarvalho commented on June 27, 2024

try updating:
'tenant_finder' => null,
to:
'tenant_finder' => Spatie\Multitenancy\TenantFinder\DomainTenantFinder::class,

from laravel-multitenancy.

wahyubaskara avatar wahyubaskara commented on June 27, 2024

Not working, same error occurred

from laravel-multitenancy.

freekmurze avatar freekmurze commented on June 27, 2024

What is the output of config('multitenancy') in a tinker session?

from laravel-multitenancy.

wahyubaskara avatar wahyubaskara commented on June 27, 2024

Sorry, how can i get the output?

from laravel-multitenancy.

freekmurze avatar freekmurze commented on June 27, 2024

Run php artisan tinker

from laravel-multitenancy.

wahyubaskara avatar wahyubaskara commented on June 27, 2024

Here is the result

Screen Shot 2020-05-29 at 23 44 43

from laravel-multitenancy.

freekmurze avatar freekmurze commented on June 27, 2024

what is the output of config('database')?

from laravel-multitenancy.

wahyubaskara avatar wahyubaskara commented on June 27, 2024

okay here is
carbon

from laravel-multitenancy.

wahyubaskara avatar wahyubaskara commented on June 27, 2024

Solved! You saved me, thank you👍

from laravel-multitenancy.

kurucu avatar kurucu commented on June 27, 2024

@wahyubaskara: try to change:

"default" => "mysql"

by

"default" => "tenant"

Oh my word, this has been tripping me up! Is this in the docs?

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

@kurucu, no, isn't in the docs because the default connection is a state of mind: depends on your project and your approach.

from laravel-multitenancy.

Saimon-git avatar Saimon-git commented on June 27, 2024

hello spatie guys and @freekmurze
I am contacting you because I have a problem with the multitenacy package, I can not get the connection to the tenant to work, I have as default connection "tenant" this is the error that I throw

SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

Screen Shot 2021-04-29 at 21 07 55

from laravel-multitenancy.

Saimon-git avatar Saimon-git commented on June 27, 2024

@Saimon-git, have you followed the documentation?

thanks @masterix21

from laravel-multitenancy.

refaatgamal avatar refaatgamal commented on June 27, 2024

I have the same error but all above i made it and still this problem exist
bruno-kelzer-LvySG1hvuzI-unsplash

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

@refaatgamal are you using the SwitchDatabaseTask?

from laravel-multitenancy.

refaatgamal avatar refaatgamal commented on June 27, 2024

Yes and now all tenants works well but I can't make landlord working but tenants works

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

@refaatgamal, I'm sure it's a misconfiguration issue. Please dig inside reading our documentation. Thanks.

from laravel-multitenancy.

arslanakram1 avatar arslanakram1 commented on June 27, 2024

@refaatgamal got any solution on this issue? I'm trying to implement the laravel multitenancy and facing the same issue that you mentioned in your last comment. Thanks

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

Sorry, but I still think that is a coding problem. Please create a GitHub repository with your sample code that generates the errors: I'll try to help asap.

from laravel-multitenancy.

Azmeer-crescent avatar Azmeer-crescent commented on June 27, 2024

I am having the exact same problem after doing this:
"default" => "tenant"

I can login to tenants but NOT to landlord account. getting the same error as:
refaatgamal commented on May 31, 2021

But when I switch the line back to:
'default' => env('DB_CONNECTION', 'mysql'),
Both landlord and tenants started working ! My DB_CONNECTION is pointing to the landlord database

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

I got this bug
Screenshot 2022-03-28 215157

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

`'default' => 'tenant',

/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'url' => env('DATABASE_URL'),
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
        'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
    ],

    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

    'tenant' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => null,
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

    'landlord' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => 'landlord',
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],`

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

@masterix21 Is there a solution to this problem ?

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

Please post your Admin model

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024
class Admin extends Authenticatable {
	use Notifiable;

	protected $table = 'admins';
	protected $fillable = [
		'email',
		'name',
		'photo_profile',
		'password',
		'group_id',
		'remember_token',
	];

	protected $hidden = ['password'];

	public function group_id() {
		return $this->hasOne(\App\Models\AdminGroup::class, 'id', 'group_id');
	}

	public function role($name) {
		$exists_group_id = $this->getConnection()
			->getSchemaBuilder()
			->hasColumn($this->getTable(), 'group_id');
		if ($exists_group_id) {
			$explode_name = explode('_', $name);

			if (!empty($this->group_id()->first())) {
				$role = $this->group_id()->first()->role()->where('name', $explode_name[0])->first();
				if (!empty($role) && $role->{$explode_name[1]} == 'yes') {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

}

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected (SQL: select * from settings order by id desc limit 1) (View: D:\delivery\resources\views\admin\login.blade.php)
I think this problem not related with Admin model

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

I created two databases and two domains
php artisan serve --port=8001

in two domain I got this problem

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

Admin model is in the landlord or in the tenant database? Why you didn't prepare your model? Take a look here: https://spatie.be/docs/laravel-multitenancy/v2/installation/using-multiple-databases#content-preparing-models

All models in your project should either use the UsesLandlordConnection or UsesTenantConnection, depending on if the underlying table of the models lives in the landlord or tenant database.

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

Ok I Will prepare the models
thanks bro ❤️❤️❤️

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

@masterix21 unfortunately the same problem
:(
I need an urgent solution

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

ok
thanks 3>

from laravel-multitenancy.

Noor600 avatar Noor600 commented on June 27, 2024

@masterix21 I created new repo and I invited you

from laravel-multitenancy.

abdallah0128318 avatar abdallah0128318 commented on June 27, 2024

@masterix21
here I have all things work very good but my problem is just I can`t migrate tenant database tables after the tenant is created
here is my code

protected static function booted()
    {
        static::creating(fn(User $model) => $model->createDatabase());
    }

    public function createDatabase()
    {
        // add logic to create database

        DB::connection()->statement('CREATE DATABASE tenant_' . $this->username);
        $this->database = 'tenant_' . $this->username;
        Artisan::call('tenants:artisan migrate --tenant=' . $this->id);
    }

from laravel-multitenancy.

masterix21 avatar masterix21 commented on June 27, 2024

How can you call $this->id if createDatabase() is called during the creating event?

from laravel-multitenancy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.