I created new postgresql user:
CREATE ROLE lara_user SUPERUSER LOGIN PASSWORD 'mypassword';
Then create schema which is owned by this user
CREATE schema lara AUTHORIZATION lara_user;
In Laravel's .env
file I have
DB_DATABASE=postgres
DB_USERNAME=lara_user
DB_PASSWORD=mypassword
Laravel don't sees schema lara
and still connected to public
schema.
How can I change and set default schema lara
for Laravel ?
The output will be, After creating a new schema, you can make it a default schema instead of a public schema. To make a schema default, the search_path variable is used. Search_path variable defines the schema order in which they are searched when an object is referenced without any schema name.
Whenever a new database is instantiated, a default schema named “public” is created. The contents of a schema include all the other database objects such as tables, views, stored procedures, triggers, and etc.
Every database starts out with one schema, the public schema. Inside that schema, the default install of PostGIS creates the geometry_columns , geography_columns and spatial_ref_sys metadata relations, as well as all the types and functions used by PostGIS. So users of PostGIS always need access to the public schema.
As of the time of this writing, the latest available version of Laravel is 6.0 LTS, and can be used with any supported version of PostgreSQL. In reality, Laravel can be used with any of several database engines because of the underlying Eloquent ORM.
in app/config/database.php
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'forge',
'username' => 'forge',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
in new version of laravel change
'schema' => 'public',
to
'search_path' => 'public',
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With