samedi 8 juin 2019

Setting up local development database with Laravel 5.7

I created a new Laravel application (Laravel 5.7) on my hosting platform, Cloudways. Cloudways is handy, because you can install new Laravel builds directly from their interface, rather than creating one locally, and pushing to the server.

At any rate, I created the build, and pulled the files down to my local machine. In previous versions of Laravel, I seem to recall just being able to edit the .env file to point to my local database (which is currently run through MAMP/phpMyAdmin)

I made sure that I created a new database, and then updated the .env file to point to that database.

However, whenever I attempt to run a migration, it still wants to point to the DB connections specified in the database.php config file.

After I updated the .env file, I DID attempt to run both:

php artisan config:clear
php artisan cache:clear

But neither seemed to have any impact. I am still getting an error every time I try to run a migration.

I can't seem to find any further documentation on how to specify a different local dev database, from the production database.

Can anybody offer any assistance?

Edit:

On MAMP, it looks like it has my local settings as:

Host:   localhost
Port:   8889
User:   root
Password:   root

My Current .env file contents:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Z2ndcYy3H7GMfmEW1rKYxYAxMMjyyAWAsoS+9Q3yppc=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=scoutsafe
DB_USERNAME=root
DB_PASSWORD=root

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

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}"

And my current database.php contents:

    return array(

    /*
    |--------------------------------------------------------------------------
    | PDO Fetch Style
    |--------------------------------------------------------------------------
    |
    | By default, database results will be returned as instances of the PHP
    | stdClass object; however, you may desire to retrieve records in an
    | array format for simplicity. Here you can tweak the fetch style.
    |
    */

    'fetch' => PDO::FETCH_CLASS,

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => 'mysql',

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => array(

            'sqlite' => array(
                    'driver'   => 'sqlite',
                    'database' => __DIR__.'/../database/production.sqlite',
                    'prefix'   => '',
            ),


            'mysql' => array(
                    'driver'    => 'mysql',
                    'host'      => '127.0.0.1',
                    'database'  => 'scoutsafe',
                    'username'  => 'root',
                    'password'  => 'root',
                    'charset'   => 'utf8',
                    'collation' => 'utf8_unicode_ci',
                    'prefix'    => '',
            ),

            'pgsql' => array(
                    'driver'   => 'pgsql',
                    'host'     => 'localhost',
                    'database' => 'forge',
                    'username' => 'forge',
                    'password' => '',
                    'charset'  => 'utf8',
                    'prefix'   => '',
                    'schema'   => 'public',
            ),

            'sqlsrv' => array(
                    'driver'   => 'sqlsrv',
                    'host'     => 'localhost',
                    'database' => 'database',
                    'username' => 'root',
                    'password' => '',
                    'prefix'   => '',
            ),

    ),

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => array(

            'cluster' => false,

            'default' => array(
                    'host'     => '127.0.0.1',
                    'port'     => 6379,
                    'database' => 0,
            ),

    ),

);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire