kevinorriss's avatar

Controller::validate unique specify postgres schema

Hi,

I am using PostgreSQL database because this is what I use at work (I am a DBA) and I like to separate sections of my website or subdomains to different schemas. For the most part this works fine, in my Model class I can do something like:

protected $table = 'tutorials.posts';

... and it works fine. Even relationships work fine so I know that Laravel can look in other schemas. The problem is that when I add a unique validation in the store function of the controller, I get the following error:

required|alpha_dash|min:5|max:255|unique:tutorials.posts

InvalidArgumentException in DatabaseManager.php line 239: Database [tutorials] not configured.

So it seems like the validation code is splitting the string and taking the schema name as the database name. I have tried specifying the database name then schema name and then table but that comes back with:

InvalidArgumentException in DatabaseManager.php line 239: Database [my_database] not configured.

Is there something I am missing or am I going to have to look into the BaseController and fiddle?

Thanks!

0 likes
4 replies
kevinorriss's avatar

I fixed it!

unique:pgsql.tutorials.posts

Where pgsql is the default database connection set up in the .env file :)

Hope this helps someone!

5 likes
anasred's avatar

Thanks for sharing this valuable information.

If you use separate schema for each tenant does Postgres creates virtual tables to each tenant? Or is it also separating auto incremental Ids to each tenant (schema)?

locopump's avatar

Thanks I applied this method in the RegisterController.php but i readed that you configure the .env file. How do I do that? or how must be my .env file?

Please or to participate in this conversation.