[Laravel] Laravel5 Quick Start Guide (1)

Source: Internet
Author: User
[Laravel] Laravel5 Quick Start Guide (I:

Laravel5 is a PHP framework called "created for WEB artists. it is favored by more and more PHPer because of its simplicity, elegance, scalability, and scalability. According to the 2015 most popular PHP Framework report, Laravel has become the most popular framework for developers.

Body:-1-about Laravel installation

Taking the Mac environment as an example, before installing Laravel, you must first install Composer and use Composer to install Laravel (note: Composer is a tool used in PHP to manage dependencies. You can declare the dependent external library (libraries) in your project. Composer will help you install these dependent library files)

The method for installing Composer is very simple. go to the official website of Composer and click the Download option. a curl Command is displayed.

  curl -sShttps://getcomposer.org/installer | php 

Copy the command to the terminal (command line tool) to download a composer. phar file. we recommend that you download the Composer and use the command

  mvcomposer.phar /usr/local/bin/composer  

Place the file in the usr/local/bin directory and use it as a global command for later directory creation.

After installing Composer, use the command in the command line tool

  composercreat-projectlaravel/laravellaravel5   

You can install Laravel successfully.

We recommend that you enable VPN before using the command.

After the installation is successful, go to the Laravel directory and run the command cd Laravel5/and artisan.

 phpartisanserve   

An http address will be returned. you can view the address and jump out of a built-in webpage. at this step, the entire installation process is complete.

-2-basic Laravel workflow

(Note: the concept of routing, controller, and view will be detailed in the following article)

When Laravel is used each time, it is first guided into a routes. php file, which is in the./app/Http Directory. three lines of code can be seen when the file is opened for the first time.

Route::get('/',function() {return  view('welcome');}); 

The three lines of code define a route (you must first define a route when starting an Http program. In the previous example, our business logic is implemented in routing, which is no problem for simple websites or web applications. when we need to expand the scale, the program becomes complicated, the hierarchical business logic is more suitable. At this time, we should use the controller)

Here '/' refers to the root directory. when the browser accesses the root directory, it will execute the content in the anonymous function.

This operation returns a view, which is saved in the./resources/views directory.

Here, welcome is a php file name, representing a php file.

Now let's create a new controller and input the command in the command line tool.

  phpartisanmake:controllerHelloController  

Return to the code editing page. you can see the new controller in the Http Controllers Directory. in HelloControllers, you can see that the system has created many methods automatically, now we can write this line of code in the index method.

 return  view('welcome'); 

And return to routes. php to write this line of code.

Route::get{'/','HelloController@index'}; 

Similarly, when accessing the root directory, the welcome page of Laravel appears.

This line of code added in routes refers to finding the index method in HelloController after accessing the root directory. @ can be understood as a call method.

Then, we will introduce Laravel and the basic usage process here,

The content of Laravel Quick Start Guide is not complete yet!

Contact me for more technical questions :)

Postscript: learning about Laravel's website recommendations

{1. http://www.golaravel.com/2. http://laravel-china.org/3.http://laravelacademy.org/about-us}

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.