Laravel registration error, database is connected, but receiving strange error - php

I have connected to my database successfully as I was able to do all of my beginning migrations, users table and password reset etc.
It is my first time running php artisan make:auth
and when I go to register a new user for the laravel application, I get this error.
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost'
(using password: YES) (SQL: select count(*) as aggregate from users
where email = ma#yahoo.com)
Here is my .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=larabiz
DB_USERNAME=root
DB_PASSWORD=
The answer was quite simple but weird.
run php artisan make:auth. then run php artisan migrate. shutdown your server, restart the server, and then register your first user. This worked for me, so Laravel was not able to add users during registration, without first restarting the server. That took me 5 fresh Laravel installs and three hours of work! I was in tears :).

The answer was quite simple but weird.
run php artisan make:auth.
then run php artisan migrate.
shutdown your server, restart the server, and then register your first user. This worked for me, so Laravel was not able to add users during registration, without first restarting the server. That took me 5 fresh Laravel installs and three hours of work! I was in tears :).

Did yout try to reload config ?
php artisan config:clear
or clear cache ?
php artisan cache:clear

Go to config/database.php and under connections set the values for your connection manually.

Related

Laravel keeps connecting to old database connection

Context :
I have DB1 and DB2 and a laravel application using DB1 so far
I want now that laravel (8) application to use DB2 instead (both DB1 & 2 are mysql)
I edited the .env file to change the DB_HOST and cleared the config cache
Expected : Laravel using DB2
Problem : Laravel still connects to DB1
Things I've tried :
php artisan config:cache / clear
php artisan optimize:clear
restarted DB1/DB2
restarted nginx
restarted php-fpm
redeployed the whole app (with composer install etc.)
tried adding a new connection in config/database.php instead of editing the existing one : same issue
hardcoding the values in config/database.php instead of referencing the env file : same issue
php artisan db sql --> connects to the RIGHT DB (this is what's driving me insane)
... but php artisan tinker doesn't seem to. I created a dummy table in DB2 only (so not present in DB1) and getting that table with \DB::connection('mysql')->table('dummy')->get(); shows an error via tinker
obviously, stopping DB1 makes the application go offline ("No such file or directory" blabla ie. no database PDO)
I don't even know what to try anymore. Every post somewhat related online are solved after a simple artisan config:clear/cache ....
Any thoughts appreciated ?
The answer was DB_SOCKET=/tmp/mysql.sock in my .env file that locked the connection to the previous (local) DB. Removing that from my env file solved the issue
to change the database you need to write the database name on DB_DATABASE instead on DB_HOST...

Deploying someone else's Laravel project (mysql connection issue)

I'm new to this business. I use ubuntu and homestead, downloaded the project and dump dump, there was no env configuration file in the folder., I took env from a clean project and entered my settings, then I ran vagrant up, vagrant ssh, went into the project folder and tried to simply execute php artisan as a result, I get this kind of message:
"In Connection.php line 664:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxxx_db.newsletter_settings' doesn't exist (SQL: select * from newsletter_settings limit 1)"
where "xxxx_db" is the database that I entered into env, and "newsletter_settings" is taken as I understood from app / Eloquent / NewsletterSettings
from the lines:
class NewsletterSetting extends Model
{
use Notifiable;
protected $table = 'newsletter_settings';
protected $primaryKey = 'id';
/**
My dear connoisseurs question: how can I tie up the project correctly?
I tried to comment out and temporarily delete the file from which the protected $ table = 'newsletter_settings' is taken;
but nothing worked.
For earlier I apologize for my english
Create Database
change db name as below
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=yourdbname
DB_USERNAME=root
DB_PASSWORD=
Run command php artisan migrate
Step 1 Artisan Cached Config Files
Try to run php artisan optimize:clear, this will clear all of your cached config files and mean any changes you make to your config files will take effect immediately.
Step 2 Manual Cached Config Files
If you cannot even run php artisan to clear the cache, you can delete them manually by removing the files within bootstrap/cache. (Keep the git ignore)
Step 3 Code Review
If the cache has no effect, then it may be that you have database calls somewhere within a boot method on one of your classes. The boot methods all run before the content of php artisan would have returned. It is not uncommon for developers who don't frequently delete their databases to fall into this trap as it won't manifest itself until someone tries to install the project from scratch.
1.Create Database
2.set database name and credentials in .env
3.Run command php artisan migrate
Thank you all, found in a separate Kernel.php this kind of string:
$setting = NewsletterSetting::first();
if(!empty($setting)) {
$schedule->command('command:newsletter')
->withoutOverlapping()
->days($setting['weekdays'])
->at($setting->send_time);
}

Clear Laravel cache(s) without Artisan command [duplicate]

This question already has answers here:
Laravel 5 – Clear Cache in Shared Hosting Server
(20 answers)
Closed 1 year ago.
I've moved my project but have run into an issue. I'm discovering that the old settings (which have been changed in my .env to reflect the changed host) are still being used by my project.
I can't access my project through a browser as it returns this error: SQLSTATE[HY000] [1045] Access denied for user 'appReop'#'localhost' (using password: YES) (SQL: select * from `settings` limit 1)
appReop was the previous login username. And while I could just create a new user to reflect this, I also run into an issue about the old password being too weak for the current database configuration.
When I go to run php artisan cache:clear, it returns the same above error. So I was curious if there was a way to manually clear the caches to fix my errors?
Update
This shows the three errors that pop up after running any Artisan command:
Not sure you have solved this, my suggestion is remove the files inside below folder. So the database connection cache file will create again after removed. (Laravel 5)
/<root>/bootstrap/cache/*
Hope it helps :)
You can call an Artisan command outside the CLI.
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('cache:clear');
// return what you want
});
You can check the official doc here http://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli
It's one time only? Just delete the folder storage/framework/cache/data
If someone still has such problem, check out your password for database. It seems like .env file does not accept # sign, that's why I had the same error.
rather batter if you could provide permission to your storage directory.
$ sudo chmod -R 777 ./storage
then remove cache and using php artisan cache:clear.I hope this will help you.
Try running:
php artisan down
php artisan config:clear
As this will place Laravel in maintenance mode and then clear only the config setting cache.
#Filippe commented about this already.
Update
Just create a file called down like in the picture below then run php artisan config:clear and then if it works php artisan up.

Laravel Artisan - reload .env variables or restart framework

I'm trying to write a command as a quickstart to build a project. The command asks for input for database details and then changes the .env file. The problem is that the command needs to do some Database queries afterwards, but the .env variables are not reloaded.
My question would be, is there a way to reload or override .env variables runtime. And if not, is there a way to call another Artisan command freshly, so framework bootstraps again?
In my command I tried doing $this->call('build:project') in my actual command, but even in the second call the variables are not reloaded.
Is there a way to achieve this without making the user manually call multiple commands?
Thanks!
i had the same problem with reloaded .env variables, and i fixed it with this command line which allow you to clear the configuration :
php artisan config:clear
Hope that helped. Regards.
Laravel uses config files which take data from .env file. So, what you can do is to override configuration values at runtime:
config(['database.default' => 'mysql']);
Try to clear cache it helped me (couldn't ssh into the server)
Is there a {app route}/bootstrap/cache/config.php file on the production server? Delete it.
This helped me
As OP I'm trying to bootstrap a Laravel project build by running console command and asking for the database credentials in the middle of the process.
This is a tricky problem and nothing I read was able to fix it : reset config, cache, Dotenv reload, etc... It seems that once the console command / operation is initialized the initial database connection is kept all over until the end.
The working solution I found is to bypass, after database modification are done, this cached state by using native shell exec command and passing the php artisan command as parameter :
passthru('php artisan migrate');
So, the order will be :
php artisan project:build (or whatever is your console command)
prompt the user for database credentials
replace values in .env file (your search & replace algorythm)
run php artisan config:cache
passthru('php artisan migrate'); ro run your migrations
shell_exec would do the same but in silent mode while passthru will return the output generated by console.
https://www.php.net/manual/en/function.passthru.php
Done successfully on Laravel 8.52

How could I migrate my database with "php artisan migrate" in laravel

I clone my project from gitlab and I make it on my new computer.
But I get nothing ouput after I run php artisan migrate and the corresponding table is not created.
Output of php artisan migrate:status below.
What the meaning of "Ran?" and why status my migration file are all "N". php artisan migrate will create these tables successfully only when the "Ran?"s are "Y"?
An Y in the Ran column means the migration has been done.
Check your .ENV file , make sure your database settings are correct, also make sure you actually created the database beforehand.
clear the entire laravel cache to stay up to date with current .env settings, it might help.
try using php artisan migrate:refresh sometime it happens with me and i find out it's already migrated

Categories