Email: info@zenconix.com

Steps by step procedure to connect the database to Lumen

Published on: 07/9/20 1:52 PM

Category:Code Laravel Lumen Tags: , ,
  1. Create database in phpmyadmin
  2. Open .env file. NOTE: if .env file is with name, .env.sample, then rename it to .env
  3. Change following parameter in file
    1. DB_DATABASE=lumen
    2. DB_USERNAME=root
    3. DB_PASSWORD=
  4. Also check for following parameters if they are different than default setting
    1. DB_HOST=127.0.0.1
    2. DB_PORT=3306
  5. Next, as we are going to use Eloquent ORM, we need to un-comment some lines from bootstrap/app.php
    1. $app→withEloquent()
    2. $app→withFacades();
  6. open command prompt, go to project location and run following command
    php artisan make:migration create_users_table
  7. It will create new file for migration in Database/migration folder, by name “DateTime_create_user_table.php
  8. If we need to add custom columns, then add as below.
public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');

            //create custom fields, we are going to add username, email and api_token
            $table->string('username');
            $table->string ('email');
            $table->text('api_token');
            $table->timestamps();
        });
    }
  1. Then run command php artisan migrate to migrate this table to database.

Reference and detailed documentation


Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

How Angular Application starts?

In this post we are going to take look on how angular application starts. For any angular application, entry point is index.html. In index.html file there is tag called as <app-root> In main.ts file <app-root> selector is picked up by the AppModule. Below is code snippet from main.ts file AppModule is module which is bootstrapped […]

Learn C# – Namespaces

What is Namespaces in C#? C# Programs are organized using namespaces. Namespaces are used to add separation of Code in C#. Namespaces can have following members inside it. Namespaces (nested) Classes Interface Delegates Structures Why to use Namespaces? Code Separation: With help of Namespaces, you can separate out set of code in C# Project.Example: if […]

Laravel – How to create Seed users

Create migration file to create new users table To create migration, open command prompt and execute following command php artisan make:migration create_users_table This will create new file in database/migration folder by name datatime_create_users_table.php Open file and modify as below. <?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Hash; class CreateUsersTable extends Migration { /** * […]