Laravel-based migrate tutorial, laravelmigrate
Preface
As we all know, the current development and testing are completed by collaboration among multiple teams. Everyone has a local environment. In the past, we generally manually add data, for example, you can use SQL statements in the database queryserver to insert data. If there is a small amount of data, it would be quite easy, but if the data is too large, it would be very painful, but it would be very easy in Laravel, you can use data migrat
following command to perform the database migration operation:php artisan migrateThe following results are obtained:If you run a command error, check the database connection settings. Now that the database migration is complete, you can open localhost/learnlaravel5/public/homeRegister and log in.6. Model ModelsNext we will touch the most powerful part of Laravel, eloquent ORM, and run the following command:php ar
excellent command-line tool called Artisan, which can be used to generate framework code and database schemas, artisan can handle everything from database schema migration to resource and configuration management.Conventions better than configurationOne of the interesting features of Laravel is that it prescribes some pretty serious restrictions on how to build a Web application. Surprisingly, these restri
quickstart --prefer-dist
Install the Quickstart project
Of course, you can also clone the GitHub repository to install it locally:
git clone https://github.com/laravel/quickstart-basic quickstartcd quickstartcomposer installphp artisan migrate
If you do not know how to build a local development environment, refer to Homestead and installation documentation.3. prepare the database 3.1 for database migration
First, let's use migration to define d
1. Introduction
Laravel contains a simple way to populate a database-using the Fill class and test data. All fill classes are located in the Database/seeds directory. The class name of the fill class is entirely customizable, but it is best to follow certain rules, such as readability, such as Usertableseeder, and so on. When Laravel is installed, a Databaseseeder class is provided by default. From this class, you can use the call method to run other fill classes, allowing you to control the fi
very famous Ang Sul to engage in the installation artifact: Https://github.com/overtrue/latest-laravel
3. Database Setup and Migration
Laravel 5 Change the location of the database configuration to ' learnlaravel5/.env ', open this file, edit the following four items and modify it to the correct information:
Db_host=localhostdb_database=laravel5db_username=rootdb_password=password
It is recommended to create a new database named Laravel5, which is recommended for direct operation with the roo
, feel free to enter your mailbox and password if you get the following picture:
Congratulations ~ Laravel 5 is successfully installed!
Do not want to configure the image of the students, you can use Laravel industry very famous anzheng Chao engaged in installation artifacts: https://github.com/overtrue/latest-laravel
3. database creation and migration
Laravel 5 changed the database configuration to 'learnlaravel5/. env'. open this file, edit the following four items, and modify them to the cor
familiarize yourself with all the configuration items.
Directory Permissions
After installing Laravel, you need to configure some directory read and write permissions: The storage and Bootstrap/cache directories should be writable, and if you use the Homestead virtual machine as the development environment, these permissions are already set.
Apply Key
The next thing to do is to set the applied key (App_key) to a random string, and if you install it through the Composer or Laravel installer,
classmate, you can use the Laravel world very famous Ang Sul to do installation artifact: Https://github.com/overtrue/latest-laravel
3. Database establishment and migration
Laravel 5 Changed the location of the database configuration to ' learnlaravel5/.env ', opened the file, edited the following four items, modified to the correct information:
Db_host=localhost
db_database=laravel5
db_username=root
Db_password=password
It is recommended to create a new database named Laravel
Laravel5 asynchronous queue usage
Laravel5 provides a complete queue function, which can be used with simple configuration. Here we will briefly record the usage of asynchronous queues.Configuration
The definition of the queue is not described here. To use Asynchronous queues, there are two key points:
1. Place the storage queue 2. Services that execute tasks
Openconfig/queue.phpThis is Laravel5's queue configuration file. First, we can usedefaultThe parameter specifies the default queue driver.
Chao engaged in installation artifacts: https://github.com/overtrue/latest-laravel
3. database creation and migration
Laravel 5 changed the database configuration to 'learnlaravel5/. env'. Open this file, edit the following four items, and modify them to the correct information:
DB_HOST=localhostDB_DATABASE=laravel5DB_USERNAME=rootDB_PASSWORD=password
We recommend that you create a database named laravel5. For the convenience of learning, we recommend that you use the root account for direct op
Simultaneous release: HTTP://EKAN001.COM/ARTICLE/26 ConfigurationThere is no introduction to the definition of the queue. We have two keys to using an asynchronous queue: 1.存储队列的地方2.执行任务的服务 Open config/queue.php , this is Laravel5 about the queue configuration file. First we can default specify the default queue driver by the parameter, the default configuration is sync , this is the synchronization queue, we want to do the asynchronous queue first change here. Assuming that we are using databas
to configure the image of the classmate, you can use the Laravel realm very famous Ang Sul to engage in the installation artifact: Https://github.com/overtrue/latest-laravel
3. Database Setup and Migration
Laravel 5 Change the location of the database configuration to ' learnlaravel5/.env ', open this file, edit the following four items and modify it to the correct information:
Db_host=localhostdb_database=laravel5db_username=rootdb_password=password
It is recommended to create a new database n
Laravel 5 framework learning-database migration (Migrations), laravelmigrations
Database migrations is one of laravel's most powerful functions. Database migration can be understood as the version controller of the database.
The database/migrations directory contains two migration files, one for creating a user table and the other for resetting the user password.
In the migration file, the up method is used to create a data table, and the down method is used to roll back the data table, that is,
1. Introduction
Laravel contains a simple way to populate a database-using fill classes and test data. All fill classes are located in the Database/seeds directory. The class name of the fill class is completely customizable, but it's best to follow certain rules, such as readability, such as Usertableseeder, and so on. When Laravel is installed, a Databaseseeder class is provided by default. From this class, you can use the call method to run other fill classes, allowing you to control the fil
Premise: This method is to use Linux crontab timed tasks to help implement Laravel scheduling (Mac also).First, add crontab scheduled Tasks, here only to do a brief introduction.Add the following with the command crontab-e/usr/local/bin/php /usr/local/var/www/projectName/artisan schedule:run >> /dev/null 2>1
1
2
:The above command crontab every minute to tune the Laravel Schedule command, and then laravel judgment to perform the task
1. Create and update table structures with migration
PHP artisan make:migration create_users_table--create=users
php artisan make:migration add_votes_to_users_table- -table=users
PHP Artisan Migrate
In practical applications, there are two ways of doing this:
A. Each time the database has any changes, execute the make:migration command to generate a new migrat
Introduction
Writing seeders
Using Model Factories
Calling Additional Seeders
Running seeders
IntroductionLaravel includes a simple method of the seeding your database with test data using seed classes. All seed classes is stored in database/seeds . Seed classes May has any name of wish, but probably should follow some sensible convention, such as UserTableSeeder , etc. By default, a-class is defined for you DatabaseSeeder . From this class, you may use the c
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.