How to create a mysql db with Laravel -
i'm using laravel 5.2. i've setup first migrations , want run them. video tutorial doesn't explain how create mysql db. know can manually in phpmyadmin there laravel way it?
this install migrations table:
php artisan migrate:install
is there similar command create db?
i'm thinking process should be:
php artisan db:install (or similar command)
install migrations table:
php artisan migrate:install
run migrations:
php artisan migrate
and rollback migrations:
php artisan migrate:rollback
nothing provided out of box make own command you:
php artisan make:console createdatabase // note, in 5.3 make:command
then in app/console/commands
you'll find createdatabase.php
. open sucker , let's make few changes:
protected $name = "make:database";
then down below in file need new function:
protected function getarguments() { return [ ['name', inputargument::required, 'the name of database'], ]; }
then we'll make function called fire()
called upon invocation of command:
public function fire() { db::getconnection()->statement('create database :schema', ['schema' => $this->argument('name')]); }
and can this:
php artisan make:database newdb
now you'll newdb
database created based on connection configuration.
edit forgot important part - need tell app\console\commands\kernel.php
new comand, make sure add protected $commands[]
array.
protected $commands = [ ///..., app\console\commands\createdatabase::class ];
Comments
Post a Comment