[Laravel] Basic HTTP routing for Laravel
Use Laravel's basic route, implement GET request response, find file app/http/routes.php
Call the route's static method get (), implement get response, parameter: path of type string, anonymous functions function () {}
Inside the anonymous function, returns the string data
Implementation of Post,put,delete's request, IBID.
Implement the Get pass parameter route, call the route's static method get (), Parameter: path, anonymous function
Path, curly brace wrap parameter name, not including $, for example: '/user/{id} '
anonymous function, receive parameter, for example: function ($id) {}
[Laravel] Laraval's Basic controller
Under the App/http/controllers directory, create a new index/indexcontroller.php
Define namespaces, Namespace App\http\controllers\index
Introduction of controller base controllers, use App\http\controllers\controller
Define Indexcontroller inherit Controller
Implementation method index, return data
Defines the behavior of the route-specific controller, for example: Route::get ("/index", "Index\indexcontroller@index");
Note In the namespace section, the newly created controller is under the root namespace, adding its own newly added namespace when specified
[Laravel] Basic view of Laravel
Under Directory resources/views/, create a index/index.php
Use Function view () in the controller to invoke the template, Parameters: File path (. delimited directory), data
Routing: routes.php
Php/*|--------------------------------------------------------------------------| Routes file|--------------------------------------------------------------------------| | Here's where you'll register all of the routes in an application.| It ' s a breeze. Simply tell Laravel the URIs it should respond to| and give it the controller to call when that URI is requested.|*//*test get post*/Route::get ('/', function () {$url=url ("Index"); return"Hello World". $url; //return view (' Welcome ');}); Route::p Ost ("/post", function () {return"Test Post";});/*Passing Parameters*/Route::get ("/user/{id}", Function ($id) {returnUser. $id;});/*using the Controller*/Route::get ("/index", "Index\indexcontroller@index");/*|--------------------------------------------------------------------------| Application routes|--------------------------------------------------------------------------| | This route group applies the "Web" middleware group to every route| It contains. The "web" middleware Group is defined in your http| Kernel and includes session state, CSRF protection, and more.|*/Route::group ([' Middleware ' = [' web ']], function () {//});
Controller: indexcontroller.php
Phpnamespace App\http\controllers\index;use App\http\controllers\controller; class extends controller{ public function Index () { $data=Array (); $data [' title ']= "index Controller"; return view ("Index.index", $data);} }
Template: index.php
< Body > < class= "container"><class= "Content" ><class= "title">
php echo $title; ?>
div>
div >
Div >
body>
The above describes the basic use of [Laravel] Laravel, including Laravel aspects of the content, I hope the PHP tutorial interested in a friend to help.