


Introduction to Laravel 5 framework learning routes, controllers and views, laravel framework_PHP tutorial
Jul 13, 2016 am 09:57 AMLaravel 5 framework learning route, controller and view introduction, laravel framework
View app/Http/routes.php
Copy code The code is as follows:
Route::get('/', 'WelcomeController@index');
@ is a delimiter, preceded by the controller and followed by the action, which means that when the user requests url /, the index method in the controller WelcomeController is executed
Copy code The code is as follows:
app/http/controllers/welcomecontroller.php
public function index()
{
return view('welcome');
}
Currently, a view is returned by default. The name of the view is welcome, which is actually welcome.blade.php. Blade is the view template of laravel.
You can view `resources/views/welcome.blade.php
Modify welcomecontroller.php
Copy code The code is as follows:
public function index()
{
// return view('welcome');
return 'hello, laravel';
}
Test in your browser and get a simple feedback.
We create a new route and add:
in routes.phpCopy code The code is as follows:
Route::get('/contact', 'WelcomeController@contact');
You can create a new route, but for now we still use the default controller directly and add:
to WelcomeController.phpCopy code The code is as follows:
public function contact() {
Return 'Contact Me';
}
Test the newly added route in the browser.
We can return a simple string, or a json or html file. All view files are stored in resource->views.
For example: return view('welcome') , we don't need to consider the path, and don't add the .blade.php extension, the framework does it for us automatically. If you need a subdirectory in the views directory, such as the views/forum subdirectory, you only need to return view('forum/xxx'), or the simple and clear way is: return view('forum.xxx'). 😄
We return to a page
Copy code The code is as follows:
public function contact() {
Return view('pages.contact');
}
Create the pages directory under the views directory, and then create contact.blade.php
Copy code The code is as follows:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>Contact</h1>
</body>
</html>
The above is the entire content of this article. I hope it will be helpful to everyone learning Laravel5.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to properly calibrate your Xbox One controller on Windows 11

Learning Laravel from scratch: Detailed explanation of controller method invocation

Java Apache Camel: Building a flexible and efficient service-oriented architecture

How to implement API routing in the Slim framework

Use JavaScript functions to implement web page navigation and routing

Implementation method and experience summary of flexibly configuring routing rules in PHP

Laravel Study Guide: Best Practices for Controller Method Calls
