Table of Contents
Laravel 5 framework learning route, controller and view introduction, laravel framework
Home Backend Development PHP Tutorial Introduction to Laravel 5 framework learning routes, controllers and views, laravel framework_PHP tutorial

Introduction to Laravel 5 framework learning routes, controllers and views, laravel framework_PHP tutorial

Jul 13, 2016 am 09:57 AM
controller routing

Laravel 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.php

Copy 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.php

Copy 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/980219.htmlTechArticleLaravel 5 framework learning route, controller and view introduction, laravel framework view app/Http/routes.php copy The code is as follows: Route::get('/', 'WelcomeController@index'); @ is a...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to properly calibrate your Xbox One controller on Windows 11 How to properly calibrate your Xbox One controller on Windows 11 Sep 21, 2023 pm 09:09 PM

How to properly calibrate your Xbox One controller on Windows 11

Learning Laravel from scratch: Detailed explanation of controller method invocation Learning Laravel from scratch: Detailed explanation of controller method invocation Mar 10, 2024 pm 05:03 PM

Learning Laravel from scratch: Detailed explanation of controller method invocation

Java Apache Camel: Building a flexible and efficient service-oriented architecture Java Apache Camel: Building a flexible and efficient service-oriented architecture Feb 19, 2024 pm 04:12 PM

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

How to implement API routing in the Slim framework How to implement API routing in the Slim framework Aug 02, 2023 pm 05:13 PM

How to implement API routing in the Slim framework

Use JavaScript functions to implement web page navigation and routing Use JavaScript functions to implement web page navigation and routing Nov 04, 2023 am 09:46 AM

Use JavaScript functions to implement web page navigation and routing

How to use routing in ThinkPHP6 How to use routing in ThinkPHP6 Jun 20, 2023 pm 07:54 PM

How to use routing in ThinkPHP6

Implementation method and experience summary of flexibly configuring routing rules in PHP Implementation method and experience summary of flexibly configuring routing rules in PHP Oct 15, 2023 pm 03:43 PM

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

Laravel Study Guide: Best Practices for Controller Method Calls Laravel Study Guide: Best Practices for Controller Method Calls Mar 11, 2024 am 08:27 AM

Laravel Study Guide: Best Practices for Controller Method Calls

See all articles