Laravel for Windows development environment configuration

Source: Internet
Author: User
Tags scale image laravel tutorial

This article is Csdn choris original, reprint please obtain the author's consent beforehand, show respect!

Original: http://blog.csdn.net/choris/article/details/50215835

laravel Configuration Tutorial

This article is based on the reference to the old Cold blog Laravel 5 Series Introductory Tutorial (a) "Best for Chinese Laravel tutorial" on the basis of written 1.

1.XAMPP integrated development Environment

Laravel is a PHP development framework, a Web site developed with the Laravel framework needs to run on an operating system with a php+ database +web server . PHP version 5.4+,mysql5.1+ is generally required. This article selects the PHP+MYSQL database +apache Web server. Under Windows you can download and install the latest version of the XAMPP integrated development environment and click on the XAMPP website to download it.

2. Installing composer

Laravel needs to use composer to manage its dependencies. Therefore, before using laravel, you must make sure that the composer is already installed on your computer.
Installing composer under Windows is simple enough to download and install the Composer-setup.exe installer as you would install XAMPP. Click to download the composer Chinese Web 2.
After the installation is complete, enter the following command to detect the installation success:

-V
3. Configure composer to use China full volume mirror

As a result of visiting a foreign site or being a wall, it is very slow and probably inaccessible if you use the default composer source directly. Fortunately, domestic IT workers have produced a full-scale image of Packagist/composer China. can refer to the composer Chinese web tutorial Configuration 3, this article will also detail the configuration steps.

There are two ways to enable this mirroring service:
  1. Add configuration information to the Composer configuration file config.json (System global Configuration)
  2. Add configuration information to a file in a single project composer.json (single item configuration)

This article chooses the first method of configuration:
Open a command-line window (Windows user) or console (Linux, Mac user) and execute the following command:

composer config-g repositories.packagist composer/http/ Packagist.phpcomposer.com    
Description

The use of this image service means that all downloaded installation package metadata will come from this mirror service and no longer request to packagist.org. This will accelerate
Composer installation process, and is more reliable and fast. (For well-known reasons, foreign sites are too slow to connect and can be wall-ready)

In general, installing package data (zip files, etc.) is typically from GitHub
or other third-party server downloaded, after using this image service, we will cache all the installation package to the domestic computer room, so that we do not have to go to foreign sites to initiate requests, so even if
Packagist.org, github.com, or other third-party services fail (mainly the connection speed is too slow and the wall is), you can still download and update the installation package.

4. Install Laravel5 using composer

After the mirroring configuration is complete, switch to the directory you want to install, and the installation path for XAMPP under Apache is:

C:\xampp\htdocs

Switch to this directory, run command prompt cmd, and enter the following command:

create-project laravel/laravel learnlaravel5 5.0.22

After the installation is complete, a directory Learnlaravel5 is generated in the current directory, as shown in:

Open the XAMPP and turn on the Apache server and enter the Laravel home directory in the browser:

public” (默认80端口可省略)在我的本机上为:localhost/learnlaravel5/public

You can see the Laravel installation interface successfully:

The
above four steps are the main steps to install the Laravel, followed by the main explanation of how to use and develop
5. Database Setup and Migration

Laravel 5 to change the location of the database configuration learnlaravel5/.env , open this file, edit the following four items, modify 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 root account for easy learning.

Laravel has prepared the Auth section of the migration for us, run the following command to perform the database migration operation:

php artisan migrate

The 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/home
Register and log in.

6. Model Models

Next we will touch the most powerful part of Laravel, eloquent ORM, and run the following command:

php artisan make:model Articlephp artisan make:model Page

In the Laravel 4 era, we used the Generator plugin to create a new Model. Now, Laravel 5 has integrated generator into the Artisan

Now, Artisan helped us to learnlaravel5/app/ create two files Article.php and Page.php , this is the two model class, they all inherit the model class provided by Laravel eloquent Illuminate\Database\Eloquent\Model , and are all \App under the namespace. It is necessary to emphasize that creating a file from the command line is no different from creating a file yourself, and you can try to create these two Model classes yourself.

Model is the M in MVC, which translates into models and is responsible for interacting with the database. In eloquent, each table in the database corresponds to a Model class (which can, of course, correspond to multiple).

If you want to learn more about eloquent, you can read the series: in-depth understanding of Laravel eloquent (a)--basic concepts and usage

Next proceed to the database migration of the article and Page classes corresponding to the articles tables and pages table, into the learnlaravel5/database/migrations folder.
Modify in ***_create_articles_table.php:

Schema:: Create (' Articles ', function (Blueprint$table) {$table->increments (' id ');$table->string ( ' title ');  $table ->string (  ' slug ') ->nullable ();  $table ->text ( ' body ') ->nullable ();  $table ->string ( ' image ') ->nullable ();  $table ->integer ( ' user_id ');  $table ->timestamps ();       

Modify in ***_create_pages_table.php:

Schema:: Create (' Pages ', function (Blueprint $table) { $table ->increments ( ' id '); Span class= "hljs-variable" > $table ->string ( $table ->string ( ' slug ') ->nullable ();  $table ->text ( ' body ') ->nullable ();  $table ->integer ( ' user_id ');  $table ->timestamps ();       

Then execute the command.

php artisan migrate

After the success, the articles table and pages tables are already present in the database.

7. Database Population Seeder

learnlaravel5/database/seeds/under new PageTableSeeder.php file, the content is as follows:

<?phpUseIlluminate\Database\Seeder;UseApp\Page;ClassPagetableseederExtendsseeder {public function run () {db::table (  ' pages ')->delete (); for ( $i =0;  $i < 10;  $i + +) {page::create ([ ' title ' =  ' title '.  $i,  ' first-page ',  body ' = =  $i,  ' user_id ' + 1,]); } }} 

Then modify the following in the same level directory DatabaseSeeder.php :

$this->call(‘UserTableSeeder‘);

This sentence is

$this->call(‘PageTableSeeder‘);

Then run the command to populate the data:

composer dump-autoloadphp artisan db:seed

View the pages table with 10 new data.

    1. Old Cold Blog Laravel 5 Series Getting Started Tutorial (a) "Best for Chinese Laravel tutorial"?
    2. Composer Chinese web?
    3. Composer Full-volume Chinese mirror?
  

Laravel for Windows development environment configuration

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.