I have used symfony2 console to create database. If I want to create a database named "symfony" I usually mentioned that name in parameters.yml file and run the below command in console
php app/console doctrine:database:create
But when came to laravel, I don't find similar command to create database in laravel. Can anyone help me to find out those command to create database directly from Laravel Console.
As far as I know, you can use
php artisan migrate
to make migrations including creating tables from Laravel Console. However, you need to create and modify migration files first, where you can create or drop tables.So if you want to create a table directly from Laravel Console using something like
php artisan create database table ***
, it is not possible.I think you can not create database through command so go to
app/config/database.php
and set your database configuration. details hereafter setting you can create table through command
it will generate a file to
app/database/migrations
name create_users_table. . . . . then you create your table following this linkand finally run this command
php artisan migrate
You can do that but you will have to create your own command.
First, run
php artisan command:make CreateDatabase --command=database:create
to generateapp/commands/CreateDatabase.php
Then open that file and change it to this: (I left out all comments, but you can obviously keep them in there)
Now you only have to register the command in
app/start/artisan.php
:and you're good to go.
That's how you call it:
Alternative: artisan tinker
You can always use
php artisan tinker
to run PHP code (with Laravel bootstrapped):