I am installing a new API with Laravel Passport using POSTGRESQL databases. When installing Laravel and basic authentication, it works ok to the point of registering users and logging in perfectly. (take the database ok, this is important!) But when following the steps to install Passport and run the "php artisan migrate" command, Passport does not recognize that I am using POSTGRESQL and looks for the connection to MYSQL, which is non-existent. I will appreciate ideas, I don't know what else to do.
ERROR:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO) (SQL:
create table `oauth_auth_codes` (`id` varchar(100) not null, `user_id` bigint unsigned not
null, `client_id` bigint unsigned not null, `scopes` text null, `revoked` tinyint(1) not
null, `expires_at` datetime null) default character set utf8mb4 collate
'utf8mb4_unicode_ci')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the
error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
I try without result:
php artisan cache:clear
php artisan config:cache
My .ENV:
#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=laravel
#DB_USERNAME=root
#DB_PASSWORD=
My CONFIG/DATABASE WITH POSTGRESQL:
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'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'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'xxxx'),
'username' => env('DB_USERNAME', 'xxxxxxxxxxx'),
'password' => env('DB_PASSWORD', 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'someschema',
'sslmode' => 'prefer',
],
I finally found the solution in a Laravel Passport forum, it seems that in the latest versions the connection to the db is configured directly in passport (I don't know why it doesn't take the one from .env or config / databases), "publishing" (exporting) from the I sell the connection file that includes the Passport Storage Driver to the app, to be able to modify it and declare the connection exclusively for Passport. Needless to say, there are 3 different places in Laravel to declare a connection to the database, subject to chatting directly with Otwell.
Anyway, this is done with the following command:
php artisan vendor:publish --tag=passport-config
which adds a file in the config folder called passport.php, and where we find, ready to configure:
/*
|--------------------------------------------------------------------------
| Passport Storage Driver
|--------------------------------------------------------------------------
|
| This configuration options determines the storage driver that will
| be used to store Passport's data. In addition, you may set any
| custom options as needed by the particular driver you choose.
|
*/
'storage' => [
'database' => [
'connection' => env('DB_CONNECTION', 'mysql'),
],
],
Related
I have my code on a local NAS at home. When I run
php artisan serve
on terminal in my desktop computer, the application starts up no problem.
However, when I am on my laptop, and I want to run the server, the following part just runs endlessly and doesn't proceed:..
Starting Laravel development server: http://127.0.0.1:8000
The reason I'm asking here is I am having a hard time knowing how to troubleshoot this issue.
The error I'm receiving when I try to load the app URL from my laptop while the terminal is still in 'starting' mode is..
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `sessions` where `id` = ZbOqp13BZNRquGtmG0Vi2XNHGWi3WDMJxW4ZYYCK limit 1)```
Also, my database.php in the config folder under mysql looks like this:
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '33060'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'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'),
]) : [],
],```
I don't see this issue mentioned on SO previously, and would appreciate ideas on how to troubleshoot this. Ideally I should be able to connect to the server fine even if I am on another computer in the same network.
Troubleshooting tips appreciated.
My .env for the database is:
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret```
I am new in Laravel. I am facing a problem to migrate my users and password reset table.
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or
access violation: 1071 Specified key was too long; max key length is
767 bytes (SQL: a lter table users add unique
users_email_unique(email))
I have tried so many solution like (AppServiceProvider, database collation change, changing migration file ) but none of them give me a solution.
AppServiceProvider.php
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
}
Database.php
'mysql' => [
'driver' => 'mysql',
'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' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
After setting defaultStringLength in AppServiceProvider maybe re-run your project with php artisan serve solve your problem.
I'm developing a Multi Tenant with Laravel v5.7 and I'm successful in sending queue emails, since my models have the property 'connection' defined.
But when trying to send, for example, an email using the Jobs class, the same fails and informs that the table of model does not exist.
From what error recorded in the table 'failed_jobs', even with the property 'connection' defined, it appears that the Job nevertheless tries to connect to the main database and not to the specified database of the property.
Is there any way to specify in Job which database to use, since the same is informed in the model?
database.php
'connections' => [
'others' => ['...']
'TENANT001' => [
'driver' => 'mysql',
'database' => env('TENANT001_DATABASE', ''),
'host' => env('TENANT001_HOSTNAME', ''),
'port' => env('DB_PORT', '3306'),
'username' => env('TENANT001_USERNAME', 'forge'),
'password' => env('TENANT001_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
Sample Model
class Template extends Model
{
/**
* The database name used by the model.
*
* #var string
*/
protected $connection = 'TENANT001';
}
failed_jobs
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'main_database.templates' doesn't exist in /www/samba/laravel.local/vendor/laravel/framework/src/Illuminate/Database/Connection.php:326
I guess you are trying to access second connection TENANT001 in Template Model.
class Template extends Model
{
/**
* The database name used by the model.
*
* #var string
*/
protected $connection = 'TENANT001';
protected $table='templates';
}
After that in your config/database.php
'connections' => [
'others' => ['...']
'TENANT001' => [
'driver' => 'mysql',
'database' => env('TENANT001_DATABASE', ''),
'host' => env('TENANT001_HOSTNAME', ''),
'port' => env('DB_PORT', '3306'),
'username' => env('TENANT001_USERNAME', 'forge'),
'password' => env('TENANT001_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Or you can use connection in the queue.php
'database' => [
'connection' => 'TENANT001'
'driver' => 'mysql',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
And clear the cache once you update .env files.
php artisan config:cache
And check you have define everything correctly in .env and table exists.
Thanks
I am new to Laravel used this https://github.com/msurguy/laravel-facebook-login link to work with facebook login in Laravel. I have setup all the things but i
got following errors when establishing database connection :
Type error: Argument 1 passed to
Illuminate\Redis\Database::__construct() must be of the type array,
null given, called in
C:\wamp64\www\laravel-facebook-login-master\vendor\laravel\framework\src\Illuminate\Redis\RedisServiceProvider.php
on line 23
I want to run simple mysql database. Below is my database.php code:
return array(
'fetch' => PDO::FETCH_CLASS,
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'facebookdb',
'username' => 'root',
'password' => '',
'port' => '3603',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
),
'migrations' => 'migrations',
);
Any suggestion/help will be highly appreciated.
You are missing the definition for your redis connection in that connections array, something like this will help:
'redis' => array(
'host' => env('REDIS_HOST', 127.0.0.1),
'port' => env('REDIS_PORT', 6379),
'password' => env('REDIS_PASSWORD', null),
'database' => env('REDIS_DATABASE', 0)
)
Make sure that you add the corresponding entries in your .env file if your redis connection settings differ from the default values above.
I have a Laravel 5 project that I copied to a new folder. I changed the database settings in the .env file. But now I am concluding that database settings are also set in vendor/config.php. What command must I run to have this regenerated? I already tried composer dump-autoload and composer update without success
The default database config is in config/database.php and looks in .env for its settings (with some fallback defaults). For example, the default MySQL connection:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Laravel does not have a vendor/config.php file.