Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 Create Database from Migration

Tags:

laravel

is there anyway I could setup(create) database from migration? I want to run migrate and seed, but beforehand it should create database first.

Any suggestions ?

Thanks

like image 926
ans4175 Avatar asked Apr 29 '16 06:04

ans4175


2 Answers

You could create custom artisan command and run it before migrate command.

Inside the command use raw query, you can try something like this:

DB::statement('CREATE DATABASE :db', ['db' => $newDatabase]);
like image 53
Alexey Mezenin Avatar answered Oct 26 '22 17:10

Alexey Mezenin


you can do this by new Artisan Command...

php artisan make:database {database-name} {connection-name}

but you have to creat this command first.

check this link

How to create new empty database with Laravel over Model

like image 36
pankaj kumar Avatar answered Oct 26 '22 18:10

pankaj kumar