1. Frame setting
first we need to set the Laravel framework, open the application/config/application.php file, we will first set the file key parameter to any 32-bit string:
- ' Key ' = ' yoursecretkeygoeshere! ',
This string will be used to encrypt our password. Then we set up the database information in application/config/database.php, where we built it beforehand, and you can name it arbitrarily:
- ' MySQL ' =>array (
- ' Driver ' = ' mysql ',
- ' Host ' = ' localhost ',
- ' Database ' = ' database ',
- ' Username ' = ' root ',
- ' Password ' = ' 123456 ',
- ' CharSet ' = ' utf8 ',
- ' Prefix ' = ',
- ),
- 2. Create a database
Then we will use the artisan and migrations tools to build the database, you can simply understand it as a database tool, before using it we need to initialize it. First, add your PHP directory to the environment variable of the system, and then open the CMD tool CD to the root of the Web to run the command:
- PHP Artisan Migrate:install
This is when we entered the database and found a table named Laravel_migrations, which records the data migrate needs. Then we run the following two commands:
- PHP Artisan Migrate:make create_admin_table
- PHP Artisan Migrate:make create_docs_table
After a successful run we can see two files named Date _creat_admin_table.php and date _creat_docs_table.php in the Application/migrations directory.
First open the creat_admin_table.php file and add the code in the Up and down methods:
- Publicfunctionup ()
- {
- Schema::create (' admin ', function ($table)
- {
- $table->increments (' id ');
- $table->string (' email ', 64);
- $table->string (' password ', 64);
- });
- Db::table (' admin ')->insert (Array (
- ' Email ' = ' your email ',
- ' Password ' =>hash::make (' Your password '),
- ));
- }
- Publicfunctiondown ()
- {
- Schema::d rop (' admin ');
- }
Re-edit the creat_docs_table.php file:
- Publicfunctionup ()
- {
- Schema::create (' Docs ', function ($table)
- {
- $table->increments (' id ');
- $table->string (' title ', 64);
- $table->text (' content ');
- $table->string (' Create_date ', 12);
- $table->string (' Last_change ', 12);
- });
- Db::table (' docs ')->insert (Array (
- ' Title ' = ' Test ',
- ' Content ' = ' Just a test! ',
- ' create_date ' =>time (),
- ' last_change ' and ' = '
- ));
- }
- Publicfunctiondown ()
- {
- Schema::d rop (' docs ');
- }
After saving, we continue to run the command:PHP artisan Migrate
Database Setup Complete
Laravel Connection Establishment Database