Laravel 5.5 multiple database connection - php

I am creating a system that has two interfaces, the admin and the landing page. In my landing page, the user can see the blogs, news that being added by the admin in the database. My problem is that I have another database that have already tables and values and i want to connect it. Should i migrate it or i will import it directly? If i migrate it how can i retain the values? Please help for my homework.
my default .env file
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:HoQcNyCc5KEGw4yjqpBIdKzTC+yeDoOJcerVMEVx+fs=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=adminpanel
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
`

In Laravel, you're able to keep two connections or migrate the data. The biggest question here is if worth migrates data to a new database.
For responding to this question I'd like to consider some points:
Do you will need to change the legacy structure?
If you responded yes, maybe it worth you migrate the structure to Laravel schema and then, restore the data in this new database.
In this case, I recommend you use a tool like mysql dump to extract the data.
Do you will have to only consume the data without change it or save new?
In this case, I recommend you to create a new Laravel connection and consume this data. Look at here
I hope that I could help you. :)

Related

Getting 500 error on Laravel MySQL application hosted on Google Cloud Platform

I have a Laravel application using MySQL hosted on Google Cloud Platform (GCP). I am successfully able to build and deploy on Google Cloud platform. I am getting 500 server error when I visit the site url. I have also created a MySQL instance and imported the SQL file.
Here is my .env file.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:+ly4U3QbWcULnj0A31g41q7Yim/L0W5olgwPbsuD1/A=
APP_DEBUG=false
APP_URL=http://127.0.0.1:8080
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tabiboba
DB_USERNAME=root
DB_PASSWORD=root
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
I dont know why am I getting 500 error. I assumed it has to do something with the database connectivity, so when I go to google cloud shell, I get Access denied for user 'root'#'35.204.189.236' (using password: YES)
Please let me know what am I missing here :(
The initial error you mentioned is for access related issue which could occur due to a variety of reasons:
Connecting to wrong host : Try to connecting the host directly and
confirm right host
User does not exist : Create a new user and try connecting
User exists but client host does not have permission to connect:Grant
permission and then try to connect using this.
Password is incorrect,or some character issue during password entry:
Try with a well known password and check for any character issue
while password is taken
You should also check if trying to access the server from a host that is different from the defined host name.Make sure that the IP address you are connecting to and from is authorized to the Cloud SQL instance, refer the documentation for information on authorizing connections
Also check Google Cloud SQL database permissions and verify that your MySQL login has been "granted" permission to login.Go to the Google Cloud SQL console>Go to the Users tab>Select your user name>Verify that the host is your public IP address or optionally use % to mean any host.
You can use the Cloud SQL Proxy to access Cloud SQL. This is secure and you do not need IP addresses for Cloud SQL.
Also check out these links for similar issue:
Error access denied for user root local host
Access denied issue CloudSql
Access denied for user using password

in flutter app android I cant register account with flutter app just login ,, the error said "wrong email or password"?

i build flutter app and link with laravel php admin on web hosting (hostgrator) . I cant register account with flutter app just login , the error said "wrong email or password" . but when change api with default seller codecanyou api :
{
"base_url": "https://multi-restaurants.smartersvision.com/",
"api_base_url": "https://multi-restaurants.smartersvision.com/api/"
}
its working 100% without any problem , just on my api problem .. my api is:
{
"api_base_url": "https://eatandgohost.com/api/",
"base_url": "https://eatandgohost.com/"
}
and my .env is :
APP_NAME='Eat & Go'
APP_ENV=local
APP_KEY=base64:*******************
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=https://eatandgohost.com/
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=yasserdh_multi_restaurants
DB_USERNAME=********
DB_PASSWORD=********
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
if you have the problem with register create account with flutter app mobile about this error "wrong email or password" or "the email is exist " , just try to change web hosting to "hostinger web hosting" , and problem fixed and mobile flutter register without any problem , thanks for all .

Swift_TransportException when when user register

I'm building my website using PyroCMS and it gives me an error when user submit his/her register form.
Swift_TransportException
Process could not be started [The system cannot find the path specified. ]
By searching about this error I found this answer. But it didn't worked for me.
Follow is my .env file fields. Is this problem with these configurations or else?
APP_ENV=local
INSTALLED=true
APP_KEY=app_key
APP_DEBUG=true
DEBUG_BAR=false
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=pyrocms
DB_USERNAME=root
DB_PASSWORD="123"
APPLICATION_NAME="Default"
APPLICATION_DOMAIN=127.0.0.1:8001
APPLICATION_REFERENCE=default
DEFAULT_LOCALE=en
APP_TIMEZONE=Asia/Colombo
APP_URL=http://127.0.0.1:8001
ADMIN_USERNAME=admin
ADMIN_EMAIL=dilushadasanayaka#gmail.com
ADMIN_PASSWORD=password
Reason for this error was I forgot to configure email setting as #Ryan said. Error was fixed when I configured my mail settings. In my case I had a gmail account. So add followings to my .env file.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=yourEmail
MAIL_PASSWORD=yourPassword
MAIL_ENCRYPTION=tls
You can read a comprehensive blog about laravel mail settings from here.

reset password works on localhost and not on web host

I'm working on a laravel project (maintenance of an existing project).
The reset password was not working.. I fixed the issue by changing the .env file on my localhost.
It was
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
I changed it to
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=email#mailtrap.io
MAIL_PASSWORD=the password
MAIL_ENCRYPTION=null
It works fine on my localhost.. When I change the .env.example on bitbucket it still doesn't work and gives me the same error
Swift_TransportException in AuthHandler.php line 181:
Failed to authenticate on SMTP server with username "noreply#igpastpapers.com" using 2 possible authenticators
Any ideas?
Make sure you change your .env file in your production code, NOT your .env.example file. The .env.example is only setup so you can see the build of your .env file wherever you keep your version control code (Git, etc), without actually having the secure data shown. Check this link out:
Environment Configuration

Laravel .env file example for godaddy

I am trying to use my project on godaddy but it is constantly giving me an error:
SQLSTATE[28000] [1045] Access denied for user 'nagesh'#'ip-address of
the website' (using password: YES) (SQL: select * from admins where
email = admin limit 1).
Although my credentials should be correct as they are created in the godaddy cpanel but still I am having this error. I searched a lot on stackoverflow and tried many solutions but nothing seems to be working. This is my .env file:
APP_ENV=local
APP_KEY=base64:Qx5MJdayISVHcd5p9nW0zJvb4BC6jyWD9BySf4j8yis=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST="IP address of the website"
DB_PORT=3306
DB_DATABASE=ncminsti_ncm
DB_USERNAME="username i created using the cpanel's add new user form"
DB_PASSWORD="password created with above user."
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
I believe am doing some mistake in my .env file. Probably the DB_Host field is wrong. I am new to laravel and not sure what should be the correct configuration for .env file. Please help me in connecting to the DB. Thank you.
If website and database are on the same server, then:
DB_HOST=127.0.0.1
You will need to try and connect to your database first:
mysql -h <thehost> -u <theuser> -p
This will either ask you to type your password or report an error. Since Laravel could not connect to your database (ultimately generating something like the above), it is safe to assume that the command above will fail. You will need to find out what the problem is, solve that and then apply the solution to your Laravel environment as well.
It is very possible that you had a typo in the username/password or defined your hostname incorrectly. It is possible that you just need to connect to localhost (127.0.0.1), but it's also possible that the server is located either on a remote computer or an image (like a Docker image). You may also need to connect to a VPN or whitelist your IP address. Try contacting your sysadmin to find out how you can connect to your database on the Command-Line Interface and once that works, apply the same idea in your Laravel config.

Categories