top of page

laravel(part3->create_model+DB Connection+migrate table in DB)

  • Writer: sondip poul singh
    sondip poul singh
  • Jan 13, 2019
  • 1 min read

As we want to set a db connection we first go to the .env file and set the dbname,username(usually root),password=""(blank). now to create every table in db we need a particular model for each. To create a model we write

php artisan make:model info -m

Model interact with the database. A model is in charge of a particular table in the database.

here info is the model name. Laravel automatically make a table names infos in the db. Conventionally we make a model name which is singular to the table name.Finally by -m we want to migrate the infos table in the database. when we type the command two new files created.

1. info.php in app

2. create_infos_table.php in database->migration

in the second one we have the following code:

public function up() { Schema::create('infos', function (Blueprint $table) { $table->increments('id'); $table->string('name',64);//added by us $table->timestamps(); }); }

we make our table format here.after saving we type

php artisan migrate

which going to migrate our infos table in db.Thats how we make a connection and tables in database.

Comments


bottom of page