Rapid Authentication and Configuration in Laravel 5.4 - php

I'm trying to add authentication to my Laravel project. My database configuration is:
'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' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
And the .env file contains:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=example
DB_USERNAME=root
DB_PASSWORD=
When I try to register, this error happens:
I'm using XAMPP and my phpMyAdmin table structure is shown in this picture:

Its because remember_token field is not allowing to store null.
so either you need to provide value for remember_token or allow remember_token to have null values.

Related

how can i use laravel multi-database?

I want to know about the laravel multiple databases. is it possible to use a default database which use only user login and after login separate group by group and every group use independent database. such as 'db' is the default database it's only for the all user login.
Example: Now 'John' is login using default database 'db'. John is the member of group1 after login john use 'db1' where stored John's all type of data. Other side Now 'Alex' login using default database 'db'. Alex is the member of group2 after login Alex use 'db2' where stored Alex's all type of data. After login default db connection no need so i want to replace 'bd' to 'db1' or 'db' to 'db2'. Please provide code for laravel
Define a separate database connection in config/database.php.
'mysql' => [ // default
'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', ''),
...
],
'db1' => [ // another
'driver' => 'mysql',
'host' => env('DB_HOST_ONE', '127.0.0.1'),
'port' => env('DB_PORT_ONE', '3306'),
'database' => env('DB_DATABASE_ONE', 'forge'),
'username' => env('DB_USERNAME_ONE', 'forge'),
'password' => env('DB_PASSWORD_ONE', ''),
...
]
Note that you have to define respective config in your .env.
Then when you want to use db1 connection it, use Config::set('database.default', 'db1'). However, it only works when you have known amount of database connections(that you can define in config/database.php), if you have unknown amount of databases, then you should change the config directly instead of the name of the connection only.
Example:
Config::set('database.connections.mysql.database', 'db1')
Config::set('database.connections.mysql.username', 'admin');
Config::set('database.connections.mysql.password', 'secret');
You can see my another answer to know how does it work underhood.
In this case, I presume you are building a system that is connecting to various existing databases possibly from different applications.
You can define as many DB connections as you want in your config/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' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'mysql2' => [
'driver' => 'mysql',
'host' => env('DB_HOST_2', '127.0.0.1'),
'port' => env('DB_PORT_2', '3306'),
'database' => env('DB_DATABASE_2', 'forge'),
'username' => env('DB_USERNAME_2', 'forge'),
'password' => env('DB_PASSWORD_2', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
...
You would however also need a way to specify for each user which other external DB from which their details are going to be fetched from, for instance a column db_name on the users table.
At the point of fetching the data of say 'Alex' User model, you can do something like
$user = User::find(1); //if Alex has user_id 1 and where $user->db_name is 'mysql2' as is in the config/database.php file
$userDetails = DB::connection($user->db_name)->where('username',$user->name)->where('other_details','some details')->get();
Make sure to specify this in your .env too, to match what's defined in config/database.php
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_HOST_2=127.0.0.1
DB_PORT_2=3306
DB_DATABASE_2=db2_name_here
DB_USERNAME_2=db2_username_here
DB_PASSWORD_2=db2_password_here
...

I can't create migration Laravel5 Access denied for user 'homestead'#'localhost' (using password: YES)

Terminal show me this message:
my env:
my database.php:
'default' => env('DB_CONNECTION', 'mysql'),
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravelup'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', '1'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
How can I solve this issue ?
Just change your .env file like this
DB_DATABASE=laravelup
DB_USERNAME=root
DB_PASSWORD= //blank here
And it will be working.
I maybe laravel configration cache problem.
If you type this command "php artisan config:clear" and try again, then it will be working.

Laravel: use database created in WAMP

I created a database using WAMP. Now I have to move everything to Laravel.
How can I use this database?
I have a lot of stored procedures written there, I would really like to use them again.
I tried changing .env file and config/database.php file, but it won't help.
config/database.php
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'db_file'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'psi'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'latin2_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
.env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_file
DB_USERNAME=root
DB_PASSWORD=psi
You don`t need to configure both env and database.php.Configure one.I recommend you to configure env file .You need a model to access the database.
Models-
https://laravel.com/docs/5.4/eloquent
Controllers-
https://laravel.com/docs/5.4/controllers#resource-controllers
Always follow the documentation

SQLSTATE[HY000] [2002] cannot connect because the computer refused the connection

I am trying to run a website in lavarel but I keep getting the error message. I have entered the correct password and username while the error occurs that the connection was refused by the computer.
.env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=''
DB_USERNAME=''
DB_PASSWORD='' db, username and ps are filled in
config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 'localhost'),
'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' => '',
'strict' => true,
'engine' => null,
],
status

laravel 5 Access denied for user 'root'#' localhost' (using password: YES)

I am new to Laravel5. I tried to create migration table but I get this error
Error Log
This is the database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'larashop'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'melody'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
and this is .env
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=larashop
DB_USERNAME=root
DB_PASSWORD=melody
Please help.
Your screenshot shows "localhost" and your code shows "127.0.0.1". MySQL treats "localhost" and "127.0.0.1" differently.
Make sure you have granted appropriate permissions for 'root'#'localhost' in your database.
http://dev.mysql.com/doc/refman/5.7/en/grant.html

Categories